<?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: Using font color in the legend of the SGPLOT procedure in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/Using-font-color-in-the-legend-of-the-SGPLOT-procedure/m-p/605819#M19131</link>
    <description>&lt;P&gt;Thanks for the clarification, Draycut.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The LEGENDITEM statement supports text as well. Here's a way to get colored text for the blue/brown labels:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;legenditem type=text name="Percent" /
      label="Percent" text="nn%" textattrs=(color=blue); 
legenditem type=text name="Mean" /
      label="Mean" text="nn" textattrs=(color=brown); 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 20 Nov 2019 16:00:01 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2019-11-20T16:00:01Z</dc:date>
    <item>
      <title>Using font color in the legend of the SGPLOT procedure</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Using-font-color-in-the-legend-of-the-SGPLOT-procedure/m-p/605747#M19125</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I want to use the color of the data (i.e mean and percent) in the legend of a plot. In this case, I want the legend in 'blue' for the percent and 'brown' for the mean. Would that be possible?&lt;/P&gt;&lt;P&gt;Please see my code below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sgplot data=top_sources_plots sganno=anno;&lt;BR /&gt;hbarparm&lt;BR /&gt;category=food&lt;BR /&gt;response=percent / datalabel&lt;BR /&gt;datalabelattrs=(color=blue)&lt;BR /&gt;fillattrs =(color=bwh)&lt;BR /&gt;outlineattrs =(color=bwh); /*variable with higher values should appear first*/&lt;BR /&gt;yaxis display=(nolabel) ;&lt;BR /&gt;hbarparm&lt;BR /&gt;category=food&lt;BR /&gt;response=mean / datalabel&lt;BR /&gt;datalabelattrs=(color=brown)&lt;BR /&gt;fillattrs =(color=bwh)&lt;BR /&gt;outlineattrs =(color=bwh);&lt;BR /&gt;xaxis display=(nolabel) ;&lt;BR /&gt;yaxis display=(nolabel);&lt;BR /&gt;keylegend /location=inside position=bottomright across=1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;AG&lt;/P&gt;&lt;DIV align="center"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Wed, 20 Nov 2019 14:40:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Using-font-color-in-the-legend-of-the-SGPLOT-procedure/m-p/605747#M19125</guid>
      <dc:creator>alexgonzalez</dc:creator>
      <dc:date>2019-11-20T14:40:27Z</dc:date>
    </item>
    <item>
      <title>Re: Using font color in the legend of the SGPLOT procedure</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Using-font-color-in-the-legend-of-the-SGPLOT-procedure/m-p/605779#M19126</link>
      <description>&lt;P&gt;Did you intentionally set the fill color for both bar charts to BWH?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2019 15:23:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Using-font-color-in-the-legend-of-the-SGPLOT-procedure/m-p/605779#M19126</guid>
      <dc:creator>DanH_sas</dc:creator>
      <dc:date>2019-11-20T15:23:30Z</dc:date>
    </item>
    <item>
      <title>Re: Using font color in the legend of the SGPLOT procedure</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Using-font-color-in-the-legend-of-the-SGPLOT-procedure/m-p/605792#M19127</link>
      <description>&lt;P&gt;What is 'bwh' in your code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regardless, the answer is 'yes' if you are running SAS 9.4M5. See the last section in the article &lt;A href="https://blogs.sas.com/content/iml/2018/12/03/tips-customize-legends-proc-sgplot.html" target="_self"&gt;"5 tips for customizing legends in PROC SGPLOT in SAS"&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;for examples of how to use the LEGENDITEM statement. You will have to specify what "shape"&amp;nbsp; (marker, line, filled area,...) to appear in the legend. In the following example, I use TYPE=LINE to plot a line, but you can change that option if you want a different choice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data top_sources_plots;
length food $10;
input food percent mean;
datalines;
bread     20 15
cheese    15 8
pasta     12 10
veggies   10 7
;

proc sgplot data=top_sources_plots ;
hbarparm
category=food response=percent / datalabel
       datalabelattrs=(color=blue)
       fillattrs =(color=bwh)
       outlineattrs =(color=bwh); /*variable with higher values should appear first*/
yaxis display=(nolabel) ;
hbarparm category=food response=mean / datalabel
      datalabelattrs=(color=brown)
      fillattrs =(color=bwh)
      outlineattrs =(color=bwh);
xaxis display=(nolabel) ;
yaxis display=(nolabel);
legenditem type=line name="Percent" /
      label="Percent" lineattrs=(color=blue); 
legenditem type=line name="Mean" /
      label="Mean" lineattrs=(color=brown); 
keylegend "Percent" "Mean" /location=inside position=bottomright across=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Nov 2019 15:35:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Using-font-color-in-the-legend-of-the-SGPLOT-procedure/m-p/605792#M19127</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2019-11-20T15:35:45Z</dc:date>
    </item>
    <item>
      <title>Re: Using font color in the legend of the SGPLOT procedure</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Using-font-color-in-the-legend-of-the-SGPLOT-procedure/m-p/605795#M19128</link>
      <description>&lt;P&gt;I did, otherwise I'd get&amp;nbsp;colors in the bars that&amp;nbsp;do not accurately represent the data. See in the attachment that in the first plot&amp;nbsp;each bar contains the mean and percent.&amp;nbsp;If you look at the&amp;nbsp;top one, for example, 11.8 is the mean (filled in red) and the percent is 21.7. Only some part of the bar is in blue, which is not accurate. That's why I think that assigning colors to the data using those colors in the legend in more accurate (see second plot).&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;AG&lt;/P&gt;&lt;DIV align="center"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Wed, 20 Nov 2019 15:37:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Using-font-color-in-the-legend-of-the-SGPLOT-procedure/m-p/605795#M19128</guid>
      <dc:creator>alexgonzalez</dc:creator>
      <dc:date>2019-11-20T15:37:41Z</dc:date>
    </item>
    <item>
      <title>Re: Using font color in the legend of the SGPLOT procedure</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Using-font-color-in-the-legend-of-the-SGPLOT-procedure/m-p/605797#M19129</link>
      <description>&lt;P&gt;Just to be clear. You want to control the color of the text in the legend, correct?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2019 15:39:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Using-font-color-in-the-legend-of-the-SGPLOT-procedure/m-p/605797#M19129</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-11-20T15:39:26Z</dc:date>
    </item>
    <item>
      <title>Re: Using font color in the legend of the SGPLOT procedure</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Using-font-color-in-the-legend-of-the-SGPLOT-procedure/m-p/605802#M19130</link>
      <description>&lt;P&gt;Why not use DISCRETEOFFSET instead of overlaying the bars? Give this a try:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sgplot data=top_sources_plots sganno=anno;
hbarparm
category=food
response=percent / datalabel
datalabelattrs=(color=blue)
fillattrs =(color=blue)
outlineattrs =(color=blue); /*variable with higher values should appear first*/
yaxis display=(nolabel) 
discreteoffset=-0.2
barwidth=0.4;
hbarparm
category=food
response=mean / datalabel
datalabelattrs=(color=brown)
fillattrs =(color=brown)
outlineattrs =(color=brown)
discreteoffset=0.2
barwidth=0.4;
xaxis display=(nolabel) ;
yaxis display=(nolabel);
keylegend /location=inside position=bottomright across=1;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Nov 2019 15:42:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Using-font-color-in-the-legend-of-the-SGPLOT-procedure/m-p/605802#M19130</guid>
      <dc:creator>DanH_sas</dc:creator>
      <dc:date>2019-11-20T15:42:59Z</dc:date>
    </item>
    <item>
      <title>Re: Using font color in the legend of the SGPLOT procedure</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Using-font-color-in-the-legend-of-the-SGPLOT-procedure/m-p/605819#M19131</link>
      <description>&lt;P&gt;Thanks for the clarification, Draycut.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The LEGENDITEM statement supports text as well. Here's a way to get colored text for the blue/brown labels:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;legenditem type=text name="Percent" /
      label="Percent" text="nn%" textattrs=(color=blue); 
legenditem type=text name="Mean" /
      label="Mean" text="nn" textattrs=(color=brown); 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Nov 2019 16:00:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Using-font-color-in-the-legend-of-the-SGPLOT-procedure/m-p/605819#M19131</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2019-11-20T16:00:01Z</dc:date>
    </item>
    <item>
      <title>Re: Using font color in the legend of the SGPLOT procedure</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Using-font-color-in-the-legend-of-the-SGPLOT-procedure/m-p/605823#M19132</link>
      <description>&lt;P&gt;Hello Rick,&lt;/P&gt;&lt;P&gt;I'm assigning the same color 'bwh' to both overlaid&amp;nbsp;bars (i.e. mean and percent). I'm using SAS EG 5.1, so it seems the 'legenditem' option is not supported.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;AG.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2019 16:09:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Using-font-color-in-the-legend-of-the-SGPLOT-procedure/m-p/605823#M19132</guid>
      <dc:creator>alexgonzalez</dc:creator>
      <dc:date>2019-11-20T16:09:45Z</dc:date>
    </item>
    <item>
      <title>Re: Using font color in the legend of the SGPLOT procedure</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Using-font-color-in-the-legend-of-the-SGPLOT-procedure/m-p/605826#M19133</link>
      <description>&lt;P&gt;Not exactly, in the plot I assigned blue color to the values of mean and brown to&amp;nbsp;percents&amp;nbsp;using datalabelattrs. What I want is that the legend specify that blue values represent mean and brown represent percent. Hope this is more clear.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2019 16:13:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Using-font-color-in-the-legend-of-the-SGPLOT-procedure/m-p/605826#M19133</guid>
      <dc:creator>alexgonzalez</dc:creator>
      <dc:date>2019-11-20T16:13:55Z</dc:date>
    </item>
    <item>
      <title>Re: Using font color in the legend of the SGPLOT procedure</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Using-font-color-in-the-legend-of-the-SGPLOT-procedure/m-p/605833#M19134</link>
      <description>&lt;P&gt;This is a good alternative, although the plot does not look as nice as with the overlaid bars.&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2019 16:31:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Using-font-color-in-the-legend-of-the-SGPLOT-procedure/m-p/605833#M19134</guid>
      <dc:creator>alexgonzalez</dc:creator>
      <dc:date>2019-11-20T16:31:29Z</dc:date>
    </item>
  </channel>
</rss>

