<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Create a line graph with multiple pair-wise p values in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/Create-a-line-graph-with-multiple-pair-wise-p-values/m-p/777946#M22224</link>
    <description>&lt;P&gt;I have done a graph like this several times, but it is always a lot of manual setup to do.&amp;nbsp; There might be a better way to automate it but I haven't looked into it.&amp;nbsp; This method manually creates the four points of each line using SERIES plots and plots the p-values with TEXT plots where the y coordinates are also manually entered.&amp;nbsp; I typically plot the boxplot or whatever kind of graph first to see where good places to put the lines would be.&amp;nbsp; Here is some example code using the CARS dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data cars;
    set sashelp.cars (where=(origin^='USA') in=a1)
        sashelp.cars (where=(origin^='Asia') in=a2)
        sashelp.cars (where=(origin^='Europe') in=a3);
    if a1 then set=1;
    else if a2 then set=2;
    else if a3 then set=3;
run;
        
        
proc npar1way data=cars;
    by set;
    class origin;
    var msrp;
    output out=pvalues;
run;

data lines;
    /**Manually create start/stop points for three series lines**/
    length x $10.;
    group=1;/**Asia/Europe**/
    x='Asia';y=95000;output;
             y=100000;output;
    x='Europe';output;
             y=95000;output;
    group=2;/**Europe/USA**/;
    x='Europe';y=110000;output;
             y=115000;output;
    x='USA';output;
             y=110000;output;
    group=3;/**Asia/USA**/
    x='Asia';y=130000;output;
             y=135000;output;
    x='USA';output;
             y=130000;output;
run;

data plot;
    merge sashelp.cars 
        lines
        pvalues (in=a);
    length xp $10.;
    if a then do;
        if set=1 then do;
            xp='Asia';
            yp=100000;/**Asia/Europe pvalue**/
        end;
        else if set=2 then do;
            xp='Europe';
            yp=115000;/**Europe/USA**/
        end;
        else if set=3 then do;            
            xp='Europe';
            yp2=135000;/**Asia/USA**/
        end;
        pvalue=catx(' ','p-value: ',p_kw);
    end;
run;


ods graphics /reset;
proc sgplot data=plot noautolegend;
    series x=x y=y /group=group lineattrs=(color=black pattern=1);
    text x=xp y=yp text=pvalue / position=top discreteoffset=0.5;
    text x=xp y=yp2 text=pvalue / position=top discreteoffset=0;
    vbox msrp / category=origin nooutliers;
    yaxis max=160000;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And the resulting graph:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="SGPlot.png" style="width: 640px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/65316i2C695CF41C625101/image-size/large?v=v2&amp;amp;px=999" role="button" title="SGPlot.png" alt="SGPlot.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that the text going into the PVALUES variable can be controlled by you for different formats, pretext, etc.&amp;nbsp; The height of the lines and amount of drop they have is also controlled by you manually.&amp;nbsp; You can add other plots like the scatter plot in your example on top of this.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
    <pubDate>Tue, 02 Nov 2021 15:49:21 GMT</pubDate>
    <dc:creator>JeffMeyers</dc:creator>
    <dc:date>2021-11-02T15:49:21Z</dc:date>
    <item>
      <title>Create a line graph with multiple pair-wise p values</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Create-a-line-graph-with-multiple-pair-wise-p-values/m-p/777936#M22223</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am trying to create a line graph using Proc SGPLOT with both overall p-value and pair-wise p-values. I was able to add the overall p-value using the INSET statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sandyzman1_0-1635864334428.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/65313i87403A5318DE8C3A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sandyzman1_0-1635864334428.png" alt="sandyzman1_0-1635864334428.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;However, I also want to add the pair-wise p-values for 3 different age groups (above graph) similar to the plot below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sandyzman1_2-1635864802392.jpeg" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/65315iD2218263AABFEDED/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sandyzman1_2-1635864802392.jpeg" alt="sandyzman1_2-1635864802392.jpeg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Is there any way to add the pair-wise p-values to the plot in SAS? Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;-Sandyzman1&lt;/P&gt;</description>
      <pubDate>Tue, 02 Nov 2021 14:54:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Create-a-line-graph-with-multiple-pair-wise-p-values/m-p/777936#M22223</guid>
      <dc:creator>sandyzman1</dc:creator>
      <dc:date>2021-11-02T14:54:19Z</dc:date>
    </item>
    <item>
      <title>Re: Create a line graph with multiple pair-wise p values</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Create-a-line-graph-with-multiple-pair-wise-p-values/m-p/777946#M22224</link>
      <description>&lt;P&gt;I have done a graph like this several times, but it is always a lot of manual setup to do.&amp;nbsp; There might be a better way to automate it but I haven't looked into it.&amp;nbsp; This method manually creates the four points of each line using SERIES plots and plots the p-values with TEXT plots where the y coordinates are also manually entered.&amp;nbsp; I typically plot the boxplot or whatever kind of graph first to see where good places to put the lines would be.&amp;nbsp; Here is some example code using the CARS dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data cars;
    set sashelp.cars (where=(origin^='USA') in=a1)
        sashelp.cars (where=(origin^='Asia') in=a2)
        sashelp.cars (where=(origin^='Europe') in=a3);
    if a1 then set=1;
    else if a2 then set=2;
    else if a3 then set=3;
run;
        
        
proc npar1way data=cars;
    by set;
    class origin;
    var msrp;
    output out=pvalues;
run;

data lines;
    /**Manually create start/stop points for three series lines**/
    length x $10.;
    group=1;/**Asia/Europe**/
    x='Asia';y=95000;output;
             y=100000;output;
    x='Europe';output;
             y=95000;output;
    group=2;/**Europe/USA**/;
    x='Europe';y=110000;output;
             y=115000;output;
    x='USA';output;
             y=110000;output;
    group=3;/**Asia/USA**/
    x='Asia';y=130000;output;
             y=135000;output;
    x='USA';output;
             y=130000;output;
run;

data plot;
    merge sashelp.cars 
        lines
        pvalues (in=a);
    length xp $10.;
    if a then do;
        if set=1 then do;
            xp='Asia';
            yp=100000;/**Asia/Europe pvalue**/
        end;
        else if set=2 then do;
            xp='Europe';
            yp=115000;/**Europe/USA**/
        end;
        else if set=3 then do;            
            xp='Europe';
            yp2=135000;/**Asia/USA**/
        end;
        pvalue=catx(' ','p-value: ',p_kw);
    end;
run;


ods graphics /reset;
proc sgplot data=plot noautolegend;
    series x=x y=y /group=group lineattrs=(color=black pattern=1);
    text x=xp y=yp text=pvalue / position=top discreteoffset=0.5;
    text x=xp y=yp2 text=pvalue / position=top discreteoffset=0;
    vbox msrp / category=origin nooutliers;
    yaxis max=160000;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And the resulting graph:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="SGPlot.png" style="width: 640px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/65316i2C695CF41C625101/image-size/large?v=v2&amp;amp;px=999" role="button" title="SGPlot.png" alt="SGPlot.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that the text going into the PVALUES variable can be controlled by you for different formats, pretext, etc.&amp;nbsp; The height of the lines and amount of drop they have is also controlled by you manually.&amp;nbsp; You can add other plots like the scatter plot in your example on top of this.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Tue, 02 Nov 2021 15:49:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Create-a-line-graph-with-multiple-pair-wise-p-values/m-p/777946#M22224</guid>
      <dc:creator>JeffMeyers</dc:creator>
      <dc:date>2021-11-02T15:49:21Z</dc:date>
    </item>
    <item>
      <title>Re: Create a line graph with multiple pair-wise p values</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Create-a-line-graph-with-multiple-pair-wise-p-values/m-p/778576#M22285</link>
      <description>JeffMyeres - Thank you so much.</description>
      <pubDate>Thu, 04 Nov 2021 18:30:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Create-a-line-graph-with-multiple-pair-wise-p-values/m-p/778576#M22285</guid>
      <dc:creator>sandyzman1</dc:creator>
      <dc:date>2021-11-04T18:30:28Z</dc:date>
    </item>
    <item>
      <title>Re: Create a line graph with multiple pair-wise p values</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Create-a-line-graph-with-multiple-pair-wise-p-values/m-p/778789#M22286</link>
      <description>&lt;P&gt;I realize that you are asking a question about adding lines and text to a graphic, but if you would like to learn about&amp;nbsp; alternative graphical methods in SAS for visualizing multiple comparisons of means, see &lt;A href="https://blogs.sas.com/content/iml/2017/10/18/diffogram-multiple-comparisons-sas.html" target="_self"&gt;"The diffogram and other graphs for multiple comparisons of means."&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Nov 2021 14:50:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Create-a-line-graph-with-multiple-pair-wise-p-values/m-p/778789#M22286</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2021-11-05T14:50:55Z</dc:date>
    </item>
  </channel>
</rss>

