08-12-2013 02:36 AM
Greetings from Australia. I have been asked by someone in my organisation to produce a 'grouped' bar/line (which I have done - see above).
Everything about it is good except that I can't work out how to change the legend label values.
We need the line legend values to be 'Males Scale B' and 'Females Scale B'
and the bar values to be 'Males Scale A' and 'Females Scale A'.
At present having the same legend for both will not be useful.
I'm hoping that we don't have to start again and use GTL since the code below has got us so close.......
Any advice appreciated.
(We are using SAS 9.3).
sgplot data=temp pad=(top=0 bottom=0 left=0 right=0);
vbar year / response=barval group=sex groupdisplay=cluster barwidth=0.85 clusterwidth=0.7 name="bars";
vline year / response=lineval group=sex y2axis name="lines" lineattrs=(thickness=2);
y2axis min=0 max=60 offsetmin=0 offsetmax=0 label='Scale B' ;
yaxis min=0 max=50 offsetmin=0 offsetmax=0.6 label='Scale A'; /***offset max says use 0.6 (60% of the axis as an offset)***/
xaxis fitpolicy=thin label='Year';
keylegend "lines" "bars"/ noborder down=2 location=inside position=topleft;
format sex sexfmt.;
08-12-2013 12:54 PM
Since the colors you are using represent the same thing, gender, I would be tempted to only display one of the legends in the KEYLEGEND statement and add a title to keylegend that would indicate look at scale A for bar and scale B for line values.
08-12-2013 01:01 PM
Another possibility would be to put the bar chart and line chart content in separate legends. Position the bar chart legend at the outside/bottom-left and the line chart legend at the outside/bottom-right. Title each legend "Scale A" and "Scale B" appropriately. The legend proximity to the correct axis and the legend title should help create the correct association.
Hope this helps!