Data visualization with SAS programming

discretelegend: How to change the legendlabel for grouped data

Accepted Solution Solved
Reply
SAS Employee
Posts: 10
Accepted Solution

discretelegend: How to change the legendlabel for grouped data

Hi there,

I customized the barchart from the customer. Now the color of the bars changes in dependent from the value (plus/minus) in red or green. I realized it in the discreteattrmap in proc template.

Now I’ve the problem with the labels of the grouped data in the legend. I can’t setting the legendlabel for this grouped data; every time I get written ‘G’ (for green) and ‘R’ (for red) in the legend.

Where can I set the label for this grouped data in the legend ?

Thank you very much in advanced

Brigitte

~~~~~~~~~~~~~~~ here the code snippet ~~~~~~~~~~~

data WORK.DATA_GRAPH;

input MONAT_TXT $ KER_GESAMT_IST_AJ BAR_COLOR $ KER_GESAMT_IST_VJ ;

datalines;

January 288425 G 300000

February -280184 R -100000

March 652716 G -50000

;

run;

proc template;

                define statgraph ker_graph;

                dynamic _MONAT_TXT

                     _KER_GESAMT_IST_VJ

                     _KER_GESAMT_IST_AJ

                    ;

                begingraph / designheight = 600 designwidth = 1200 border = false;

                entrytitle _id='title' halign=left 'Jahresverlauf operatives Ergebnis' /

                           textattrs=(weight=bold style=normal size=9 family='Arial');

                /* Bars farbig, je nach Wert  */

                discreteattrmap name="colorbysign";

                     value 'G' /fillattrs=(color=green) ;

                     value 'R' /fillattrs=(color=red) ;

                enddiscreteattrmap;

                discreteattrvar attrvar=signvar var=BAR_COLOR attrmap="colorbysign" ;

                layout lattice _id='lattice' /

                     columndatarange=data columngutter=10 rowdatarange=data rowgutter=10;

                layout overlay _id='overlay' /

                       barchart     _id='bar'     x=_MONAT_TXT y=_KER_GESAMT_IST_AJ  /

                                group=signvar legendlabel='XXXXX'

                                dataskin=gloss

                                barlabel=true

                                barlabelattrs=(color=BLACK style=NORMAL family='Arial' size=9

                                barwidth=0.5

                                name='bar'

                                ;

                       seriesplot   _id='series'  x=_MONAT_TXT y=_KER_GESAMT_IST_VJ  /

                                connectorder=xaxis

                                display=(markers)

                                lineattrs=(color=BLUE THICKNESS=3)

                                markerattrs=(symbol=CIRCLEFILLED color=BLUE size=9)

                                name='series';

                 endlayout;

                sidebar /

                    align=bottom spacefill=false;

                       discretelegend _id='legend' 'bar'  'series' /

                       border=true displayclipped=true halign=center opaque=true valign=center

                      valueattrs=(color=BLACK style=NORMAL family='Arial' size=9);

                endsidebar;

                endlayout;

                endgraph;

                end;

           run;

proc sgrender data  = WORK.DATA_GRAPH

          template = KER_GRAPH;

               dynamic            _MONAT_TXT = "MONAT_TXT" 

           _KER_GESAMT_IST_VJ  = "KER_GESAMT_IST_VJ"

                _KER_GESAMT_IST_AJ  = "KER_GESAMT_IST_AJ" 

           ;

           run;


Accepted Solutions
Solution
‎01-16-2012 09:23 AM
SAS Super FREQ
Posts: 925

discretelegend: How to change the legendlabel for grouped data

LEGENDLABELs do not work in group variable situation. I'm not sure what you want in your legend. Typically, you would use the real group values in the DISCRETEATTRMAP and those values would show up in the legend. If your trying to use group for positive/negative, you can use the terms like "positive" and "negative" in your data and have that appear in the legend. If you want to create a legend that has no connection to the group variable, there is a way in SAS 9.3 to create a custom legend entry that can be associated with a legend instead of your bar chart. Just let me know what you desire in your legend.

View solution in original post


All Replies
Solution
‎01-16-2012 09:23 AM
SAS Super FREQ
Posts: 925

discretelegend: How to change the legendlabel for grouped data

LEGENDLABELs do not work in group variable situation. I'm not sure what you want in your legend. Typically, you would use the real group values in the DISCRETEATTRMAP and those values would show up in the legend. If your trying to use group for positive/negative, you can use the terms like "positive" and "negative" in your data and have that appear in the legend. If you want to create a legend that has no connection to the group variable, there is a way in SAS 9.3 to create a custom legend entry that can be associated with a legend instead of your bar chart. Just let me know what you desire in your legend.

SAS Employee
Posts: 10

discretelegend: How to change the legendlabel for grouped data

Hi Dan,

thank you very much for your suggestion!

I change the terms in my data to "positive volume of sale" and "negative volume of sale"  ==> this works fine and I think this will be OK for my customer.

Best regards,

Brigitte

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 651 views
  • 0 likes
  • 2 in conversation