<?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: SGPLOT series makes zig zag trajectories in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-series-makes-zig-zag-trajectories/m-p/950239#M25123</link>
    <description>&lt;P&gt;Create separate Y variable values for each treatment and separate REG plot statements for each as well without any group variable as a work around.&lt;/P&gt;</description>
    <pubDate>Fri, 08 Nov 2024 17:15:16 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2024-11-08T17:15:16Z</dc:date>
    <item>
      <title>SGPLOT series makes zig zag trajectories</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-series-makes-zig-zag-trajectories/m-p/950231#M25121</link>
      <description>&lt;P&gt;I've seen this problem a couple of times when I try to make a spaghetti plot (series for every individual). When I run the code below, the graph ends up with back-and-forth trajectories as if people are traveling backwards in time. I also tried SORT, but it does not seem to help. Any help or advice would be most appreciated!&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data long;
call streaminit(1234);
do p = 1 to 50; * persons;
	* personal intercept;
	int = 10 + 2 * rand("Normal"); 
	* personal slope;
	slo = 1 + rand("Normal"); 

	* treatment dummy;
	if p LT 25 then trt = 0;
	else trt = 1;

	* time loop;
	do t = 1 to 6; 
		*regression model;
		Y = int + (t-1) * slo    	/* basic growth */
			+ .2 * trt * (t-1)**2 	/* treatment effect */
			+ 1.5 * rand("Normal"); 	/* time-specific error*/
		output;
	end;
end;
run;

proc sort data=long; by p t; run;
* spaghetti plot;
proc sgplot data=long noautolegend;
series Y = Y X = t / group = p lineattrs=(color=ligr pattern=1);
reg Y = Y X = t / group = trt nomarkers;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The result shows trajectories going back and forth in time (X).&lt;/P&gt;</description>
      <pubDate>Fri, 08 Nov 2024 16:07:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-series-makes-zig-zag-trajectories/m-p/950231#M25121</guid>
      <dc:creator>BranumMartin</dc:creator>
      <dc:date>2024-11-08T16:07:04Z</dc:date>
    </item>
    <item>
      <title>Re: SGPLOT series makes zig zag trajectories</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-series-makes-zig-zag-trajectories/m-p/950237#M25122</link>
      <description>&lt;P&gt;Looks buggish to me.&amp;nbsp; You might want to submit to tech support.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That sometimes happens if you have too many groups, but in that case you get a warning in the log.&amp;nbsp; That doesn't seem to be the problem here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you comment out the REG plot, you get don't get the connected zigzag.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sgplot data=long noautolegend;
  series Y = Y X = t / group = p lineattrs=(color=ligr pattern=1);
*  reg Y = Y X = t / group = trt nomarkers;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you leave the reg plot but change it to group by P, you don't get the zigzag:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sgplot data=long noautolegend;
  series Y = Y X = t / group = p lineattrs=(color=ligr pattern=1);
  reg Y = Y X = t / group = p nomarkers;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you replace the reg plot with a scatter plot, you don't get the zigzag&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sgplot data=long noautolegend;
  series Y = Y X = t / group = p lineattrs=(color=ligr pattern=1);
  scatter Y = Y X = t /group=trt ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So seems like there is an odd interaction (bug-ish) where having the REG plot overlaid and using a different GROUP variable is causing a problem for the SERIES plot grouping.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Nov 2024 16:44:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-series-makes-zig-zag-trajectories/m-p/950237#M25122</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2024-11-08T16:44:55Z</dc:date>
    </item>
    <item>
      <title>Re: SGPLOT series makes zig zag trajectories</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-series-makes-zig-zag-trajectories/m-p/950239#M25123</link>
      <description>&lt;P&gt;Create separate Y variable values for each treatment and separate REG plot statements for each as well without any group variable as a work around.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Nov 2024 17:15:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-series-makes-zig-zag-trajectories/m-p/950239#M25123</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-11-08T17:15:16Z</dc:date>
    </item>
    <item>
      <title>Re: SGPLOT series makes zig zag trajectories</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-series-makes-zig-zag-trajectories/m-p/950244#M25124</link>
      <description>&lt;P&gt;You left art out in your sort. Try sorting by "trt p &amp;nbsp;t", and see if you get what you expect.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Nov 2024 17:37:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-series-makes-zig-zag-trajectories/m-p/950244#M25124</guid>
      <dc:creator>DanH_sas</dc:creator>
      <dc:date>2024-11-08T17:37:58Z</dc:date>
    </item>
    <item>
      <title>Re: SGPLOT series makes zig zag trajectories</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-series-makes-zig-zag-trajectories/m-p/950245#M25125</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=long; 

by TRT p t;  /* this seems to be doing the trick */

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Nov 2024 17:47:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-series-makes-zig-zag-trajectories/m-p/950245#M25125</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-11-08T17:47:33Z</dc:date>
    </item>
    <item>
      <title>Re: SGPLOT series makes zig zag trajectories</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-series-makes-zig-zag-trajectories/m-p/950246#M25126</link>
      <description>&lt;P&gt;Interestingly, dataset LONG &lt;EM&gt;is&lt;/EM&gt; already sorted by&amp;nbsp;&lt;SPAN&gt;&lt;FONT face="courier new,courier"&gt;trt p t&lt;/FONT&gt;, yet&amp;nbsp; sorting by &lt;FONT face="courier new,courier"&gt;trt&lt;/FONT&gt; makes a difference to the plot. So, apparently PROC SGPLOT uses the sort information &lt;EM&gt;metadata&lt;/EM&gt;.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Nov 2024 17:56:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-series-makes-zig-zag-trajectories/m-p/950246#M25126</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-11-08T17:56:13Z</dc:date>
    </item>
    <item>
      <title>Re: SGPLOT series makes zig zag trajectories</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-series-makes-zig-zag-trajectories/m-p/950247#M25127</link>
      <description>&lt;P&gt;Here is the full explanation of what you saw:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Grouped fits (reg, loess, and pbspline) must be sorted by their group values to be processed correctly. If the data is not already in the correct order, the procedure will sort it internally. For scatter plots (which are typically used), this has no impact. However, for a SERIES plot, this can cause the line to go backwards to follow the data. The best practice for this special case is to sort your data, starting with the group variable from the fit.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Nov 2024 17:57:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-series-makes-zig-zag-trajectories/m-p/950247#M25127</guid>
      <dc:creator>DanH_sas</dc:creator>
      <dc:date>2024-11-08T17:57:27Z</dc:date>
    </item>
    <item>
      <title>Re: SGPLOT series makes zig zag trajectories</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-series-makes-zig-zag-trajectories/m-p/950248#M25128</link>
      <description>&lt;P&gt;Correct,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Nov 2024 17:59:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPLOT-series-makes-zig-zag-trajectories/m-p/950248#M25128</guid>
      <dc:creator>DanH_sas</dc:creator>
      <dc:date>2024-11-08T17:59:57Z</dc:date>
    </item>
  </channel>
</rss>

