<?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: Legend as annotation? in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/Legend-as-annotation/m-p/635588#M19692</link>
    <description>&lt;P&gt;First thing to do would be to show how you are creating the base of the graph to start.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are procs that create graphs that have fewer options than others.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many of the SGPLOT or SGPANEL plots have the CURVELABEL= option to attach text with CURVELABELATTRS= to control color and font of the label and CURVELABELLOC= with options of INSIDE or OUTSIDE to place the label inside or outside of the plot axis and CURVELABELPOS= for which x value (start, end, min, max) to place the label near&lt;/P&gt;</description>
    <pubDate>Sun, 29 Mar 2020 08:06:09 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-03-29T08:06:09Z</dc:date>
    <item>
      <title>Legend as annotation?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Legend-as-annotation/m-p/635585#M19691</link>
      <description>&lt;P&gt;Any suggestions on how to create this type of plot? (Not too fussed about the text colours, but being able to attach legends at the right of crowded graphs would be great).&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BruceBrad_0-1585465079011.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/37495i587753D089AF327C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="BruceBrad_0-1585465079011.png" alt="BruceBrad_0-1585465079011.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 29 Mar 2020 07:05:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Legend-as-annotation/m-p/635585#M19691</guid>
      <dc:creator>BruceBrad</dc:creator>
      <dc:date>2020-03-29T07:05:11Z</dc:date>
    </item>
    <item>
      <title>Re: Legend as annotation?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Legend-as-annotation/m-p/635588#M19692</link>
      <description>&lt;P&gt;First thing to do would be to show how you are creating the base of the graph to start.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are procs that create graphs that have fewer options than others.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many of the SGPLOT or SGPANEL plots have the CURVELABEL= option to attach text with CURVELABELATTRS= to control color and font of the label and CURVELABELLOC= with options of INSIDE or OUTSIDE to place the label inside or outside of the plot axis and CURVELABELPOS= for which x value (start, end, min, max) to place the label near&lt;/P&gt;</description>
      <pubDate>Sun, 29 Mar 2020 08:06:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Legend-as-annotation/m-p/635588#M19692</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-03-29T08:06:09Z</dc:date>
    </item>
    <item>
      <title>Re: Legend as annotation?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Legend-as-annotation/m-p/635607#M19693</link>
      <description>&lt;P&gt;Thanks. I hadn't come across the curvelabel option before. It does what I want, though the positioning algorithm isn't quite perfect.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BruceBrad_0-1585476460355.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/37500i390A11B673960E56/image-size/medium?v=v2&amp;amp;px=400" role="button" title="BruceBrad_0-1585476460355.png" alt="BruceBrad_0-1585476460355.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 29 Mar 2020 10:08:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Legend-as-annotation/m-p/635607#M19693</guid>
      <dc:creator>BruceBrad</dc:creator>
      <dc:date>2020-03-29T10:08:33Z</dc:date>
    </item>
    <item>
      <title>Re: Legend as annotation?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Legend-as-annotation/m-p/635853#M19695</link>
      <description>&lt;P&gt;It is almost never a waste of time to post the code that you are using to create output. Then we don't have to guess about options used.&lt;/P&gt;
&lt;P&gt;I suspect that if you do something to increase the values shown on the Y axis you may get a little more space so that the collision you show for Spain and Italy no longer occurs. There are a number of things that SAS uses to create the actual graph display area and I suspect that the Curvelabel positioning is determined &lt;STRONG&gt;after&lt;/STRONG&gt; the graph space is determined. So if there is more vertical axis space set aside then the label has a bit more room.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Mar 2020 15:37:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Legend-as-annotation/m-p/635853#M19695</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-03-30T15:37:00Z</dc:date>
    </item>
    <item>
      <title>Re: Legend as annotation?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Legend-as-annotation/m-p/635899#M19696</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; I know this is marked as being solved already but it looked like a fun challenge to try to make.&amp;nbsp; Here's my take on it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I used STOCKS from the SASHELP library to make this graph:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sgplot data=sashelp.stocks;
    series x=date y=close / group=stock lineattrs=(pattern=solid);
run;&lt;/CODE&gt;&lt;/PRE&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/37548iA854B8D4ECA38B8B/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;I then used the following code to use annotation to make the connecting lines and labels as you were looking for.&amp;nbsp; It's not perfect and not really universal at the moment, but might give a start if you're looking for something.&amp;nbsp; It basically sets up the labels (stocks in this case) in ranked order from the maximum date and prints them in an axis table.&amp;nbsp; The graph then sets aside space for the connecting lines at the end of the series plot (using offsetmax in the x-axis) and uses DRAWLINE to connect the end of each curve to their label.&amp;nbsp; The axis table is drawn on the y2 axis in another panel so that percentages can be used in the draw lines to line things up.&amp;nbsp; Hopefully this isn't too confusing:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sort data=sashelp.stocks out=rank;
    by descending close stock;
    where date=mdy(12,1,2005);
run;

data plot_prep;
    set rank end=last;
    by descending close stock;
    if first.stock then rank+1;
    if last.stock then call symputx(catx('_','y',rank),close);
    if last then call symputx('ngroups',rank);
run;
%put &amp;amp;=y_1  &amp;amp;=y_2 &amp;amp;=y_3 &amp;amp;=ngroups;

proc sort data=plot_prep;
    by stock;
data plot;
    merge sashelp.stocks plot_prep;
    by stock;
    if ^first.stock then call missing(rank);
run;
   
%macro connect_lines;
    %do i = 1 %to 3;
        /*First horizontal line*/
        drawline x1=81 x2=%sysevalf(80+20*&amp;amp;i/(1+&amp;amp;ngroups)) y1=&amp;amp;&amp;amp;y_&amp;amp;i  y2=&amp;amp;&amp;amp;y_&amp;amp;i / lineattrs=(pattern=solid thickness=1pt color=grey) x1space=layoutpercent x2space=layoutpercent 
            y1space=datavalue y2space=datavalue;
        /*Vertical line*/
        drawline x1=%sysevalf(80+20*&amp;amp;i/(1+&amp;amp;ngroups)) x2=%sysevalf(80+20*&amp;amp;i/(1+&amp;amp;ngroups)) y1=&amp;amp;&amp;amp;y_&amp;amp;i  y2=%sysevalf(99-100*&amp;amp;i/10) / 
            lineattrs=(pattern=solid thickness=1pt color=grey) x1space=layoutpercent x2space=layoutpercent 
            y1space=datavalue y2space=datapercent;
        /*Second horizontal line*/
        drawline x1=%sysevalf(80+20*&amp;amp;i/(1+&amp;amp;ngroups)) x2=100 y1=%sysevalf(99-100*&amp;amp;i/10) y2=%sysevalf(99-100*&amp;amp;i/10) / 
            lineattrs=(pattern=solid thickness=1pt color=grey) x1space=layoutpercent x2space=layoutpercent 
            y1space=datapercent y2space=datapercent;
    %end;
%mend;
options mprint;
ods path WORK.TEMPLAT(UPDATE) SASHELP.TMPLMST (READ);
proc template;
    define statgraph series_label;
    begingraph;
    
    layout lattice / rows=1 columns=2 columnweights=(0.9 0.10) rowdatarange=union columngutter=0;
        rowaxes;
            rowaxis / type=linear display=(ticks tickvalues label) linearopts=(tickvaluesequence=(start=0 end=225 increment=25) viewmin=0 viewmax=225) offsetmin=0 offsetmax=0;
        endrowaxes;
        layout overlay/walldisplay=none  yaxisopts=(type=linear linearopts=(tickvaluesequence=(start=0 end=225 increment=25) viewmin=0 viewmax=225) offsetmin=0 offsetmax=0)
            y2axisopts=(type=linear display=none linearopts=(viewmin=0 viewmax=10) reverse=true offsetmin=0 offsetmax=0)
            xaxisopts=(display=(ticks tickvalues label) offsetmax=0.2);
            seriesplot x=date y=close / group=stock lineattrs=(pattern=solid);
            drawline x1=0 x2=100 y1=0 y2=0 / x1space=wallpercent x2space=datapercent y2space=datavalue y1space=datavalue lineattrs=(color=grey pattern=solid thickness=1pt);
            drawline x1=0 x2=0 y1=0 y2=100 / drawspace=wallpercent lineattrs=(color=grey pattern=solid thickness=1pt);
            %connect_lines;
        endlayout;
        
        layout overlay/ walldisplay=none xaxisopts=(display=none) y2axisopts=(type=linear display=none linearopts=(viewmin=0 viewmax=10) reverse=true offsetmin=0 offsetmax=0);
            axistable value=stock y=rank / colorgroup=stock yaxis=y2 display=(values);
            scatterplot x=date y=close / markerattrs=(size=0pt);
        endlayout;
    endlayout;
    endgraph;
    end;
run;

proc sgrender data=plot template=series_label;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="SGRender.png" style="width: 640px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/37549iAF00E8500DC9460F/image-size/large?v=v2&amp;amp;px=999" role="button" title="SGRender.png" alt="SGRender.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I redrew the y axis with drawline also because when using ROWDATARANGE=union there's an annoying feature where it draws the y axis line in every panel, which I don't want in this case.&amp;nbsp; I redrew the x-axis because otherwise there would be a longer blank line after the 2006 due to using offsets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Mar 2020 17:44:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Legend-as-annotation/m-p/635899#M19696</guid>
      <dc:creator>JeffMeyers</dc:creator>
      <dc:date>2020-03-30T17:44:47Z</dc:date>
    </item>
  </channel>
</rss>

