<?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: Background color of legend in sgplot in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Background-color-of-legend-in-sgplot/m-p/801656#M315510</link>
    <description>&lt;P&gt;Or if you want make backcolor be LTGRAY ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;PROC SGPLOT DATA = SASHELP.HEART ;
styleattrs datacontrastcolors=(red blue green magenta yellow black)
WALLCOLOR=LTGRAY&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt; backcolor=LTGRAY&lt;/STRONG&gt;&lt;/FONT&gt;
             datasymbols=(x x x circle circle circle Triangle Triangle Triangle);
   SERIES X = weight Y = height / markers lineattrs=(pattern=solid) markerattrs=(size=11) group = bp_status;
   keylegend/position=bottom   valueattrs=( family=arial size=12pt) down=3 &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;NOOPAQUE &lt;/FONT&gt; &lt;/STRONG&gt;

;
run;&lt;/PRE&gt;</description>
    <pubDate>Fri, 11 Mar 2022 13:04:44 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2022-03-11T13:04:44Z</dc:date>
    <item>
      <title>Background color of legend in sgplot</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Background-color-of-legend-in-sgplot/m-p/801643#M315506</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;
&lt;P&gt;My plot has WALLCOLOR=LTGRAY. Is it possible to have that color as background in the legend too?&lt;/P&gt;
&lt;P&gt;Here is a part of the syntax:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SGPLOT DATA = DB;
styleattrs datacontrastcolors=(red blue green magenta yellow black) WALLCOLOR=LTGRAY
             datasymbols=(x x x circle circle circle Triangle Triangle Triangle);
   SERIES X = date Y = Wert / markers lineattrs=(pattern=solid) markerattrs=(size=11) group = Nr;
   keylegend/position=bottom valueattrs=(family=arial size=12pt) down=3;
...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Best regards &lt;span class="lia-unicode-emoji" title=":dove:"&gt;🕊&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Antje&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2022 12:00:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Background-color-of-legend-in-sgplot/m-p/801643#M315506</guid>
      <dc:creator>AntjeWestphal</dc:creator>
      <dc:date>2022-03-11T12:00:20Z</dc:date>
    </item>
    <item>
      <title>Re: Background color of legend in sgplot</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Background-color-of-legend-in-sgplot/m-p/801654#M315509</link>
      <description>&lt;P&gt;Do you mind to put it inside graph ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;   keylegend/position=bottom valueattrs=( family=arial size=12pt) down=3 &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;location=inside&lt;/STRONG&gt;&lt;/FONT&gt;;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Mar 2022 12:56:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Background-color-of-legend-in-sgplot/m-p/801654#M315509</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-03-11T12:56:41Z</dc:date>
    </item>
    <item>
      <title>Re: Background color of legend in sgplot</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Background-color-of-legend-in-sgplot/m-p/801656#M315510</link>
      <description>&lt;P&gt;Or if you want make backcolor be LTGRAY ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;PROC SGPLOT DATA = SASHELP.HEART ;
styleattrs datacontrastcolors=(red blue green magenta yellow black)
WALLCOLOR=LTGRAY&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt; backcolor=LTGRAY&lt;/STRONG&gt;&lt;/FONT&gt;
             datasymbols=(x x x circle circle circle Triangle Triangle Triangle);
   SERIES X = weight Y = height / markers lineattrs=(pattern=solid) markerattrs=(size=11) group = bp_status;
   keylegend/position=bottom   valueattrs=( family=arial size=12pt) down=3 &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;NOOPAQUE &lt;/FONT&gt; &lt;/STRONG&gt;

;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Mar 2022 13:04:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Background-color-of-legend-in-sgplot/m-p/801656#M315510</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-03-11T13:04:44Z</dc:date>
    </item>
    <item>
      <title>Re: Background color of legend in sgplot</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Background-color-of-legend-in-sgplot/m-p/801660#M315513</link>
      <description>&lt;P&gt;Thanks, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;!&lt;/P&gt;
&lt;P&gt;If there is no other option to get only a grey background of the legend, I would choose your second idea.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2022 13:46:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Background-color-of-legend-in-sgplot/m-p/801660#M315513</guid>
      <dc:creator>AntjeWestphal</dc:creator>
      <dc:date>2022-03-11T13:46:10Z</dc:date>
    </item>
    <item>
      <title>Re: Background color of legend in sgplot</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Background-color-of-legend-in-sgplot/m-p/801686#M315524</link>
      <description>&lt;P&gt;The KEYLEGEND statement does not support to set the background. Proc SGPLOT code is translated into the Graph Template Language (GTL), on this level it is possible to set the background of the legend.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How to get the GTL from Proc SGPLOT, add the TMPLOUT= option, see below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sgplot data=sashelp.class tmplout="c:\temp\sgplot.sas";
  styleattrs
  datacontrastcolors=(red blue green magenta yellow black) WALLCOLOR=LTGRAY
    datasymbols=(x x x circle circle circle Triangle Triangle Triangle);
  series x=age y=height / group=sex;
  keylegend / location=outside ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Have a look at the resulting file, this the GTL code used to create the graph.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now adapt the code by adding the BACKGROUND= option to the DISCRETELEGEND statement, see below for an example.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods path
  (prepend) work.mytemplates (update)
;

proc template;
define statgraph sgplot;
begingraph / collation=binary subpixel=on dataContrastColors=( CXFF0000 CX0000FF CX008000 CXFF00FF CXFFFF00 CX000000 ) dataSymbols=( X X X CIRCLE CIRCLE CIRCLE TRIANGLE TRIANGLE TRIANGLE );
layout overlay / WallColor=CXC0C0C0 yaxisopts=(labelFitPolicy=Split) y2axisopts=(labelFitPolicy=Split);
   SeriesPlot X='Age'n Y='Height'n / primary=true Group='Sex'n LegendLabel="Height" NAME="SERIES";
   DiscreteLegend "SERIES" / Location=Outside Title="Sex" backgroundcolor=ltgray;
endlayout;
endgraph;
end;
run;

proc sgrender data=sashelp.class template=sgplot;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2022 15:49:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Background-color-of-legend-in-sgplot/m-p/801686#M315524</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2022-03-11T15:49:54Z</dc:date>
    </item>
    <item>
      <title>Re: Background color of legend in sgplot</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Background-color-of-legend-in-sgplot/m-p/802331#M315849</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32"&gt;@BrunoMueller&lt;/a&gt;!&lt;/P&gt;
&lt;P&gt;I never used proc template before and I have to become acquainted with it.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 20:03:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Background-color-of-legend-in-sgplot/m-p/802331#M315849</guid>
      <dc:creator>AntjeWestphal</dc:creator>
      <dc:date>2022-03-15T20:03:44Z</dc:date>
    </item>
    <item>
      <title>Re: Background color of legend in sgplot</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Background-color-of-legend-in-sgplot/m-p/802511#M315936</link>
      <description>&lt;P&gt;As a general rule always start with proc SGPLOT, SGPANEL etc. Only if there is not other way I would go for the Graph Template Language.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2022 17:48:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Background-color-of-legend-in-sgplot/m-p/802511#M315936</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2022-03-16T17:48:47Z</dc:date>
    </item>
    <item>
      <title>Re: Background color of legend in sgplot</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Background-color-of-legend-in-sgplot/m-p/802514#M315937</link>
      <description>&lt;P&gt;Actually there is any easier way which does not involve any GTL, but defining your own style, check out the sample below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*
 * have a look at the default style definition
 * search for graphlegendbackground
 */
proc template;
  source styles.default;
run;

/*
 * now create your own style based on the default style you use
 * just change the definition for GraphLegendBackground
 */
proc template;
  define style mystyle;
    parent=styles.htmlblue;
    class GraphLegendBackground /
      backgroundcolor = ltgray
      color = ltgray
  ;
  end;
run;

/*
 * now create the graph using your own style definition
 * et voilà
 */
ods html5 file="c:\temp\legendbackground.html"
          style=mystyle
      ;
      
proc sgplot data=sashelp.class tmplout="c:\temp\sgplot.sas";
  styleattrs
  datacontrastcolors=(red blue green magenta yellow black) WALLCOLOR=LTGRAY
    datasymbols=(x x x circle circle circle Triangle Triangle Triangle);
  series x=age y=height / group=sex;
  keylegend / location=outside ;
run;
ods html5 close;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also check this paper,&amp;nbsp;&lt;A href="https://support.sas.com/resources/papers/proceedings17/SAS0675-2017.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings17/SAS0675-2017.pdf&lt;/A&gt;, on the various style elements being used.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2022 18:32:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Background-color-of-legend-in-sgplot/m-p/802514#M315937</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2022-03-16T18:32:09Z</dc:date>
    </item>
    <item>
      <title>Re: Background color of legend in sgplot</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Background-color-of-legend-in-sgplot/m-p/803058#M316207</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32"&gt;@BrunoMueller&lt;/a&gt; Great, it works perfectly! Thanks for your input and the paper!&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2022 11:33:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Background-color-of-legend-in-sgplot/m-p/803058#M316207</guid>
      <dc:creator>AntjeWestphal</dc:creator>
      <dc:date>2022-03-21T11:33:16Z</dc:date>
    </item>
  </channel>
</rss>

