07-28-2014 07:06 PM
Greetings from Australia.
I produced the following grouped bar chart using SGPLOT.
Not convinced its the best way to present such data but I just do as I'm told :-)
It needs some stylising which I can easily do.
However, where I work has very strict style requirements. One being that if the bars in the chart have no outline, then the "bars" in the legend must also have no outline. (and for coloured bars, no outline is the requirement).
The SGPLOT code I used was
sgplot data=fig_ageSpeo_rates /*noautolegend*/;
vbar age_group/response=value group=qty_sex groupdisplay=cluster barwidth=1 nooutline;
yaxis min=0 max=5000 offsetmax=0 label='Rate';
keylegend/noborder position=top across=4 location=outside;
Does anyone know an easy way to get the legend 'squares' to not have an outline? (like you would get with SAS\Graph).
I did something with GTL and LEGENDITEMS but that seems way too complicated for most of our users here to have to grapple with.
All advice appreciated. Am using SAS9.3 on a windows server. I do also have access to SAS 9.4.
07-28-2014 08:20 PM
You can work around this behavior by making the outline color to be the same as the background instead of using NOOUTLINE. Try specifying OUTLINEATTRS=(color=white) and see if you get what you want.
Hope it helps!
07-29-2014 06:49 PM
That works nicely on 9.4. outlineattrs seems to only be in 9.4 though? Some of users are still on 9.3 (a long story).
I'm guessing there's no 9.3 workaround?
07-29-2014 07:54 PM
There are two ways.
1. Derive a new style from the one you like and set the GraphOutlines contrastcolor to the same as the GraphWalls color.
2. From SGPLOT, write out the GTL code using TMPLOUT='filename.sas'. In the GTL code, in the BARCHARTPARM statement, set the OutlineAttrs=(color=GraphWalls:contrastcolor), just like you did in SG.
07-29-2014 10:17 PM
Thanks for the prompt reply late in your day Sanjay. Much appreciated.
I tried option1 but it didn't seem to do anything. Could you specify the exact syntax for me please?
Option2 works but then with the white outline it now looks like there is a space between the grouped bars, which is not what we want.
Using the outlineattrs option Dan mentioned (in 9.4), did not introduce the 'space' issue though.
07-30-2014 11:57 AM
We dug deeper to review what was happening. Here is the scoop:
With SAS 9.4, the legend color swatch outlines use the OutlineAttrs. SGPLOT also supports OutlineAttrs option, so you can use the following code to get the results you want. Swatches can be made bigger by setting AutoItemSize AND increasing the legend value font size. No change to a style is needed.
proc sgplot data=sashelp.cars;
vbar origin / group=type response=mpg_city stat=mean groupdisplay=cluster outlineattrs=(thickness=0 color=white);
keylegend / autoitemsize valueattrs=(size=12);
We discovered that at SAS 9.3, swatch outlines are determined internally. A work around is possible for a special case that has only bar charts in the graph.
07-31-2014 12:24 AM
Thanks (again) for following up Sanjay.
Is the workaround for 9.3 the one you have already mentioned (in no.3 of this discussion) or something else?
If its the workaround in no.3 are you able to provide the exact syntact for point 1 of that post?
07-31-2014 01:04 AM
I tried (in SAS9.3) outlineattrs=(color=white thickness=0) in GTL but it still drew a white "outline" and hence there was a small gap between bars (and the legend squares looked a bit small). I verified this by changing the color to red. The outline appeared. It seems that (in 9.3) for the outlineattrs in GTL thickness of 0 is in fact the same as 1.
07-31-2014 10:02 AM
The work around needed to overcome the built in logic is more complicated and will only work if you have a graph that has only a Bar Chart, without combining with other plot types. It is kind of ugly, so I hesitate to even go there unless this is necessary, and it fits the above restriction. Is removing the legend swatch outline really important?