05-30-2013 12:43 PM
I have a horizontal bar chart that has very long data labels so that the chart itself is truncated. Is there a way to either wrap the text or expand the right side of the graph?
I used proc sgplot because I want the groups to be stacked on top of one another, which I don't think is possible in proc gchart.
Please see have.png for what the chart looks like and want.png as an example of how I'd like it to look.
05-30-2013 01:17 PM
05-30-2013 01:17 PM
06-13-2013 02:01 PM
I'm having an issue with ordering the data using the split option. I'd like the chart to be in descending order, but when I add that option (in bold) the split stops working. Any suggestions?
axis1 label=none value=none;
axis2 label=none value=(justify=right) split='\' order=descending;
proc gchart data=foo;
hbar colorvar / discrete type=sum sumvar=my_value subgroup=colorvar
group=label space=0 maxis=axis1 gaxis=axis2;
06-14-2013 08:08 AM
"order=descending" is not a valid option to put on the axis statement. The log shows the following...
332 axis2 label=none value=(justify=right) split='\' order=descending;
ERROR 22-322: Syntax error, expecting one of the following: a quoted string, a numeric constant,
a datetime constant, (.
ERROR 76-322: Syntax error, statement will be ignored.
06-14-2013 09:19 AM
Thanks Robert. How do I get the data in the order I want it in? I want to reorder the group variable by descending. I've sorted the data by the group variable before running the chart and that doesn't work. I've added the descending option to the options after the '/' in the hbar statement and that doesn't work either.
06-14-2013 09:56 AM
The 'descending' option orders by bar heights, not the labels.
To sort the groups in a certain order, you'll either have to hard-code the values in the order= of the group's axis statement, such as ...
axis2 order=('the group I want first' 'the group I want second' 'and so on');
Or you could assign numeric values to correspond to the groups, and make those numeric values in the order you want, and plot them instead of the text groups ... and then use a user-defined-format to make those numeric values show up as the text values.
Or, if you're not too picky about the exact text, you might could pre-pend something that will help you force the default alphabetical order to sort in the way you want (such as pre-pending a '1: ' and a '2:', and so on) in front of your text values.
Also, there's a bug related to specifying custom order for values >32 characters in SAS 9.2 ... this bug is fixed in SAS 9.3 - hopefully you're using 9.3!
06-14-2013 10:17 AM
Thanks, I used the order= option in the axis statement. Luckily, I do have 9.3! I found that if I used formats then SAS will order by the alphabetical order of the format, not the underlying value. And I had to wrap the text, and the split statement doesn't work with formats. Please correct me if I'm wrong. Thanks for your help!
06-14-2013 10:21 AM
Ahh - now that I think about it, you are correct! For bar charts, the bar ordering is done on the formatted value, rather than the underlying numeric value. I had entered a 'bug' on that in 2005, but the developers say it's working as intended
05-30-2013 01:19 PM
Yes, you can make a stacked group bar chart with GCHART. Use SUBGROUP option. With SGPLOT you can use HBAR to place labels from another variable, but there is no way to automatically wrap long data Labels. If you can split the labels yourself, you can use SGANNO.
05-30-2013 02:47 PM
I am curious about SGANNO. I know how to add that to the sgplot procedure, but I don't know how to format the annotated dataset so that this will work properly. Can you point me to an example?
05-30-2013 03:05 PM
Here is an article using SGANNO. It works mostly like annotate, with a few differences. i suggest you look up the doc, or Ch 9 of the SGPROCEDURES book. The TEXT function wraps text within the specified width. So you don't have to split the text, just specify a wrapping width.