I'm generating a plot. On the x-axis is a variable with numbers 1 thru 7. But it has a format, so the plot shows the formatted names instead of 1 thru 7.
But the problem is that using the words on the x-axis makes it too long. So instead of using the words for all of 1 thru 7, it'll use just the names for 1, 3, 5 and 7 and leave out the ones for 2, 4 and 6.
It seems to me that one way around this would be to put the words on two lines instead of one. So instead of this being below the x-axis
Operating Equipment
we could put this
Operating
Equipment
It would take up two lines in the up and down direction but it would take up less space left to right and thus there would be room for all seven formatted values instead of just those for 1, 3, 5 and 7.
Is that possible? What do you think? Any help is appreciated. I can attach the code if you like but I have a feeling that will not be necessary in this case since it's pretty straightforward.
If PROC SGPLOT, you can make the size of the plot wider and/or taller. Example:
ods graphics/width=8in height=6in;
This may eliminate the problem. You can use trial and error to determine the best height and width. Making the font size smaller might also help, but normally smaller text has its own disadvantages and isn't a good solution. Also look at the FITPOLICY and VALUESROTATE options in the SGPLOT XAXIS documentation.
Back to my original point, don't make us guess or assume what PROC you are using. Come right out and tell us.
I'm using proc sgplot. I've never heard of FITPOLICY the other person mentioned. I'll look into it. I'll be making a bunch of plots so something that is general would be helpful. If it was just one or two then I'd consider things like reducing the font but I don't think that's feasible when making a bunch of them.
In the XAXIS statement the FITPOLICY controls some of that sort of appearance. FITPOLICY=SPLIT or SPLITALWAYS with the options SPLITCHAR='*' and having the values include an * where you want to break the text.
The difference between SPLIT and SPLITALWAYS is if the text would fit without splitting the SPLIT doesn't (which can result in ugly labels with the split character in the label). Note that the split character can be in a FORMAT VALUE definition and work as well.
data example; X="Long label*for a*value on*the Xaxis"; y=3; output; x='Another long*value for the*Xaxis'; y=1; output; run; proc sgplot data=example; scatter x=x y=y ; xaxis fitpolicy=splitalways splitchar='*'; run;
FitPolicy looks promising but the problem is that I don't have a text string that goes on the x-axis, like in your example, and instead I have a numeric variable (1 thru 7) that has a format and it is the formatted values that are too long and that I'd like to go on separate rows. Any remedy for that?
That said, if worse comes to worse I could make a character variable and use it for the x-axis but it would be a pain since I'll be generating a lot of graphs.
@n6 wrote:
FitPolicy looks promising but the problem is that I don't have a text string that goes on the x-axis, like in your example, and instead I have a numeric variable (1 thru 7) that has a format and it is the formatted values that are too long and that I'd like to go on separate rows. Any remedy for that?
I haven't used FITPOLICY in many years. Are you sure it doesn't work with formatted values?
Please make a little example like @ballardw showed, but closer to your situation. Not real data, just a DATA step that makes a few rows, the PROC format code, and the PROC SGPLOT code showing the problem. If you can post the code for that small example, it will make it easier for others to help.
@n6 wrote:
FitPolicy looks promising but the problem is that I don't have a text string that goes on the x-axis, like in your example, and instead I have a numeric variable (1 thru 7) that has a format and it is the formatted values that are too long and that I'd like to go on separate rows. Any remedy for that?
Formats will work but you need to specify a DISCRETE axis
data example; X=1; y=3; output; x=2; y=1; output; run; Proc format library=work; value forsplit 1="Long label*for a*value on*the Xaxis" 2='Another long*value for the*Xaxis' ; run; proc sgplot data=example; scatter x=x y=y ; format x forsplit.; xaxis type=discrete fitpolicy=splitalways splitchar='*'; run;
That works beautifully. Thanks.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: