<?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: How to prevent datalabels from colliding / overlapping in series graph by group? in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/How-to-prevent-datalabels-from-colliding-overlapping-in-series/m-p/921393#M24499</link>
    <description>&lt;P&gt;Thanks for the great suggestions,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15130"&gt;@DanH_sas&lt;/a&gt;&amp;nbsp; and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I used Dan's strategy and I am almost there. Any ideas on why the LEFT datalabel wants to sit exactly on the line? Is there a way to pad it over to the left a little bit?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again!&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="Figure100.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/94854i2890385518B549A7/image-size/large?v=v2&amp;amp;px=999" role="button" title="Figure100.png" alt="Figure100.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;		*GRAPH - All;
		ods listing gpath='\\Figures\' image_DPI=300;
		ods graphics / reset 
			height=6.5in imagename="Figure100&amp;amp;Z" imagefmt=PNG ATTRPRIORITY=NONE ANTIALIASMAX=378300;
		Footnote justify=left height=1.2 font="Times New Roman" "Figure X.XX. Survival Function";
		Title;

		proc sgplot data=SurvivalPlotOffType noborder;

	    series x=Time y=Survival /
			lineattrs=(pattern=solid)
			Group=Stratum
			Name='S';
		scatter x=Time y=Quartiles /
			markerattrs=(symbol=circle size=7)
			name='Q';
		text x=Time y=Quartiles text=Years /
			group=stratum
			textattrs=(size=10)
			position=PositionVar;
		keylegend 'Q' /
			location=inside
			position=right
			Valueattrs=(Size=10);
		yaxis label="Survival Probability"
			grid values=(0 to 1 by 0.10);
		xaxis label="Years"
			grid values=(0 to 20 by 2);
		run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 21 Mar 2024 20:02:13 GMT</pubDate>
    <dc:creator>samp945</dc:creator>
    <dc:date>2024-03-21T20:02:13Z</dc:date>
    <item>
      <title>How to prevent datalabels from colliding / overlapping in series graph by group?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/How-to-prevent-datalabels-from-colliding-overlapping-in-series/m-p/921354#M24492</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm creating a series graph with a group variable and using the DATALABEL option to add quartile values to the graph. I believe SAS uses an algorithm to automatically avoid colliding as described in this blog post and elsewhere:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/graphicallyspeaking/2017/12/08/advanced-ods-graphics-applying-position-option-scatter-plots/" target="_blank"&gt;https://blogs.sas.com/content/graphicallyspeaking/2017/12/08/advanced-ods-graphics-applying-position-option-scatter-plots/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, the quartile datalabel values that I created are colliding for the two groups.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why isn't the automatic collision avoidance working for me?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think I can use the advice at the above-linked blog to manually alter datalabel positions, but I need to produce quite a few of these graphs with different data and would like to use the automatic collision avoidance if possible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your help!&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="Figure100.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/94843i326FC20A737AC084/image-size/large?v=v2&amp;amp;px=999" role="button" title="Figure100.png" alt="Figure100.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;		*GRAPH - All;
		ods listing gpath='\\Figures\' image_DPI=300;
		ods graphics / reset 
			height=6.5in imagename="Figure100&amp;amp;Z" imagefmt=PNG ATTRPRIORITY=NONE ANTIALIASMAX=378300;
		Footnote justify=left height=1.2 font="Times New Roman" "Figure X.XX. Survival Function";
		Title;

		proc sgplot data=SurvivalPlot noborder;

	    series x=Time y=Survival /
			lineattrs=(pattern=solid)
			Group=Stratum
			datalabel=Years
			datalabelattrs=(size=10)
			Name='S';
		scatter x=Time y=Quartiles /
			markerattrs=(symbol=circle size=7)
			name='Q';
		keylegend 'Q' /
			location=inside
			position=right
			Valueattrs=(Size=10);
		yaxis label="Survival Probability"
			grid values=(0 to 1 by 0.10);
		xaxis label="Years"
			grid values=(0 to 20 by 2);
		run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Mar 2024 17:38:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/How-to-prevent-datalabels-from-colliding-overlapping-in-series/m-p/921354#M24492</guid>
      <dc:creator>samp945</dc:creator>
      <dc:date>2024-03-21T17:38:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to prevent datalabels from colliding / overlapping in series graph by group?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/How-to-prevent-datalabels-from-colliding-overlapping-in-series/m-p/921356#M24493</link>
      <description>&lt;P&gt;How about creating input data set with two separate variables, one for each "Stratum" value, and then create two SERIES plots, one with "DATALABELPOS=LEFT" and other with "DATALABELPOS=RIGHT" ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;{EDIT:}&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  do Time=1 to 5;
    Quartiles1 = time;
    Quartiles2 = time;
    Quartiles1lab = "A" !! put(time*10,5.2-l);
    Quartiles2lab = "B" !! put(time*20,5.2-l);
    output;
  end;
run;

proc sgplot data=have;
scatter x=Time y=Quartiles1 / datalabel=Quartiles1lab
			markerattrs=(symbol=circle size=7) DATALABELPOS=LEFT;
scatter x=Time y=Quartiles2 / datalabel=Quartiles2lab
			markerattrs=(symbol=circle size=7) DATALABELPOS=RIGHT;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2024 17:53:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/How-to-prevent-datalabels-from-colliding-overlapping-in-series/m-p/921356#M24493</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-03-21T17:53:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to prevent datalabels from colliding / overlapping in series graph by group?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/How-to-prevent-datalabels-from-colliding-overlapping-in-series/m-p/921370#M24494</link>
      <description>&lt;P&gt;Another option would be to use your existing data structure, but add a TEXT plot so that you can control the label positions from your data. The code&amp;nbsp;would look something like the following.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sgplot data=SurvivalPlot noborder;

	    series x=Time y=Survival /
			lineattrs=(pattern=solid)
			Group=Stratum
			Name='S';
		scatter x=Time y=Quartiles /
			markerattrs=(symbol=circle size=7)
			name='Q';
		text x=Time y=Survival text=years  / group=stratum
                        textattrs=(size=10) position=PositionVar;
		keylegend 'Q' /
			location=inside
			position=right
			Valueattrs=(Size=10);
		yaxis label="Survival Probability"
			grid values=(0 to 1 by 0.10);
		xaxis label="Years"
			grid values=(0 to 20 by 2);
		run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You would just need to add a PositionVar to your data specifying where you want the each label (LEFT, RIGHT, TOPRIGHT, BOTTOMLEFT, etc.).&lt;/P&gt;
&lt;P&gt;Hope this helps!&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2024 18:23:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/How-to-prevent-datalabels-from-colliding-overlapping-in-series/m-p/921370#M24494</guid>
      <dc:creator>DanH_sas</dc:creator>
      <dc:date>2024-03-21T18:23:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to prevent datalabels from colliding / overlapping in series graph by group?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/How-to-prevent-datalabels-from-colliding-overlapping-in-series/m-p/921393#M24499</link>
      <description>&lt;P&gt;Thanks for the great suggestions,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15130"&gt;@DanH_sas&lt;/a&gt;&amp;nbsp; and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I used Dan's strategy and I am almost there. Any ideas on why the LEFT datalabel wants to sit exactly on the line? Is there a way to pad it over to the left a little bit?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again!&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="Figure100.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/94854i2890385518B549A7/image-size/large?v=v2&amp;amp;px=999" role="button" title="Figure100.png" alt="Figure100.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;		*GRAPH - All;
		ods listing gpath='\\Figures\' image_DPI=300;
		ods graphics / reset 
			height=6.5in imagename="Figure100&amp;amp;Z" imagefmt=PNG ATTRPRIORITY=NONE ANTIALIASMAX=378300;
		Footnote justify=left height=1.2 font="Times New Roman" "Figure X.XX. Survival Function";
		Title;

		proc sgplot data=SurvivalPlotOffType noborder;

	    series x=Time y=Survival /
			lineattrs=(pattern=solid)
			Group=Stratum
			Name='S';
		scatter x=Time y=Quartiles /
			markerattrs=(symbol=circle size=7)
			name='Q';
		text x=Time y=Quartiles text=Years /
			group=stratum
			textattrs=(size=10)
			position=PositionVar;
		keylegend 'Q' /
			location=inside
			position=right
			Valueattrs=(Size=10);
		yaxis label="Survival Probability"
			grid values=(0 to 1 by 0.10);
		xaxis label="Years"
			grid values=(0 to 20 by 2);
		run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Mar 2024 20:02:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/How-to-prevent-datalabels-from-colliding-overlapping-in-series/m-p/921393#M24499</guid>
      <dc:creator>samp945</dc:creator>
      <dc:date>2024-03-21T20:02:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to prevent datalabels from colliding / overlapping in series graph by group?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/How-to-prevent-datalabels-from-colliding-overlapping-in-series/m-p/921396#M24500</link>
      <description>&lt;P&gt;On the TEXT statement, try add these two options:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;STRIP -- this option strips extra spaces from the text. I think that is why you are getting a difference between the LEFT and RIGHT positioned text&lt;/LI&gt;
&lt;LI&gt;PAD=10px -- This will pad out the text by 10 px. You can adjust this to taste.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Thu, 21 Mar 2024 20:11:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/How-to-prevent-datalabels-from-colliding-overlapping-in-series/m-p/921396#M24500</guid>
      <dc:creator>DanH_sas</dc:creator>
      <dc:date>2024-03-21T20:11:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to prevent datalabels from colliding / overlapping in series graph by group?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/How-to-prevent-datalabels-from-colliding-overlapping-in-series/m-p/921399#M24501</link>
      <description>&lt;P&gt;Can you share your plot data set?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the &amp;lt;/&amp;gt; icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm wondering if you are getting something related to different size plot elements, text and symbol combined with the default justification of numeric values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/415445"&gt;@samp945&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for the great suggestions,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15130"&gt;@DanH_sas&lt;/a&gt;&amp;nbsp; and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I used Dan's strategy and I am almost there. Any ideas on why the LEFT datalabel wants to sit exactly on the line? Is there a way to pad it over to the left a little bit?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2024 20:25:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/How-to-prevent-datalabels-from-colliding-overlapping-in-series/m-p/921399#M24501</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-03-21T20:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to prevent datalabels from colliding / overlapping in series graph by group?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/How-to-prevent-datalabels-from-colliding-overlapping-in-series/m-p/921402#M24502</link>
      <description>&lt;P&gt;Thanks for your help,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The dataset is quite large so I have attached the code as a text file.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2024 20:42:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/How-to-prevent-datalabels-from-colliding-overlapping-in-series/m-p/921402#M24502</guid>
      <dc:creator>samp945</dc:creator>
      <dc:date>2024-03-21T20:42:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to prevent datalabels from colliding / overlapping in series graph by group?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/How-to-prevent-datalabels-from-colliding-overlapping-in-series/m-p/921439#M24504</link>
      <description>&lt;P&gt;You could put these datalabel into a SCATTER statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
call streaminit(123);
 do Time=1 to 100;
   Group=1;
   x=rand('uniform');
   y=pdf('normal',x);
   _x=.;_y=.;year=.;
   if Time in (2  3 5 20 40 80 95 99) then do;_x=x;_y=y;year=2.45;end;
   output;
   Group=2;
   x=x+0.005;
   y=y+0.001;
   _x=.;_y=.;year=.;
   if Time in (2  3 5 20 40 80 95 99) then do;_x=x;_y=y;year=2.45;end;
   output;
 end;
run; 


proc sort data=have ;by group x;run;
proc sgplot data=have noborder;
series x=x y=y /lineattrs=(pattern=solid) Group=Group;
scatter x=_x y=_y/datalabel=year group=group ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1711076913230.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/94863i34757D76E7E5F423/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1711076913230.png" alt="Ksharp_0-1711076913230.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2024 03:08:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/How-to-prevent-datalabels-from-colliding-overlapping-in-series/m-p/921439#M24504</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-03-22T03:08:39Z</dc:date>
    </item>
  </channel>
</rss>

