Hi
I have made this following figure. Im quite unsure how to do the legend as one box for blue and one box for red .I get this colurs from colorresponse but my group variable is different. Can some one plz help?
My code below:
proc template;
define statgraph bw_profile;
dynamic title;
begingraph / designwidth=1100 designheight=640 border = off;
entrytitle "Figure 1" / textattrs=(color=black family="Courier New" size=9pt weight=normal);
entrytitle "xxxxxxxxxxx " / textattrs=(color=black family="Courier New" size=9pt weight=normal);
entrytitle "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy" / textattrs=(color=black family="Courier New" size=9pt weight=normal);
entryfootnote halign = left " " /textattrs=(size=8 ) ;
entryfootnote halign = left " " /textattrs=(size=8 ) ;
entryfootnote halign = left " " /textattrs=(size=8 ) ;
entryfootnote halign = left "MFSAF = Myelofibrosis Symptom Assessment Form (MFSAF) V4.0; OL = Open Label."/ textattrs=(color=black family="Courier New" size=9pt weight=normal);
entryfootnote halign = left "Program: f_xx_ab48_ir.sas" halign=right " Page 1 of 1" / textattrs=(color=black family="Courier New" size=9pt weight=normal) ;
layout lattice / rowdatarange=data columns=1 rows=2 rowweights = (.95 .05);
layout overlay / cycleattrs=true
yaxisopts = (label = 'Change from Baseline, %' offsetmin = 0.015 offsetmax = 0.015
linearopts = (tickvalueformat=ytfmt. viewmin =-100 viewmax = 100 tickvaluesequence=(start=-100 end=100 increment=10)))
xaxisopts = (display=none);
barchart category=id response=pchg / group=ESMMB groupdisplay=cluster colorresponse=resp colormodel=(blue red)
name='waterfall' /*dataskin=gloss filltype=gradient*/
barlabelattrs=(size=6pt weight=bold)
fillattrs=(color=gray)
outlineattrs=(color=gray)
clusterwidth=0.8;
referenceline y=-50/ lineattrs=(pattern=mediumdash) ;
referenceline x=&yref / lineattrs=(pattern=mediumdash);
endlayout;
layout overlay / cycleattrs=true
xaxisopts = (display=none)
yaxisopts = (display=none) walldisplay = none;
seriesplot x=id y=myy/lineattrs=(thickness = 0);
drawtext "&danlbl (N= %left(&pop3))" /y=1 x=8 width=18 xspace=wallpercent;
drawtext "&mmblbl (N= %left(&pop2))" /y=1 x=45 width=18 xspace=wallpercent;
endlayout;
endlayout;
endgraph;
end;
run;
Without data or the values of some macro variables much less an Sgrender call I cannot test any code.
I think that if you modify this:
barchart category=id response=pchg / group=ESMMB groupdisplay=cluster colorresponse=resp colormodel=(blue red) name='waterfall' /*dataskin=gloss filltype=gradient*/ barlabelattrs=(size=6pt weight=bold) fillattrs=(color=gray) outlineattrs=(color=gray) clusterwidth=0.8;
to add a Name that a Discretelegend statement can associate with your chart such as
barchart category=id response=pchg / group=ESMMB groupdisplay=cluster colorresponse=resp colormodel=(blue red) name='waterfall' /*dataskin=gloss filltype=gradient*/ barlabelattrs=(size=6pt weight=bold) fillattrs=(color=gray) outlineattrs=(color=gray) clusterwidth=0.8 name='bars'; discretelegend 'bars';
That you will get a default legend. Add options to discretelegend as needed.
Note: it is a good idea to paste code into a text box opened on the forum with the </> icon above the message window to preserver formatting.
Without data or the values of some macro variables much less an Sgrender call I cannot test any code.
I think that if you modify this:
barchart category=id response=pchg / group=ESMMB groupdisplay=cluster colorresponse=resp colormodel=(blue red) name='waterfall' /*dataskin=gloss filltype=gradient*/ barlabelattrs=(size=6pt weight=bold) fillattrs=(color=gray) outlineattrs=(color=gray) clusterwidth=0.8;
to add a Name that a Discretelegend statement can associate with your chart such as
barchart category=id response=pchg / group=ESMMB groupdisplay=cluster colorresponse=resp colormodel=(blue red) name='waterfall' /*dataskin=gloss filltype=gradient*/ barlabelattrs=(size=6pt weight=bold) fillattrs=(color=gray) outlineattrs=(color=gray) clusterwidth=0.8 name='bars'; discretelegend 'bars';
That you will get a default legend. Add options to discretelegend as needed.
Note: it is a good idea to paste code into a text box opened on the forum with the </> icon above the message window to preserver formatting.
Thanks @ballardw . I used legenditem and discretelegend and it worked.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.