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.
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;
"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.
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.
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!
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!
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
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.
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.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.