BookmarkSubscribeRSS Feed
n6
Quartz | Level 8 n6
Quartz | Level 8

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.

10 REPLIES 10
PaigeMiller
Diamond | Level 26

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.

 

 

--
Paige Miller
n6
Quartz | Level 8 n6
Quartz | Level 8

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.

ballardw
Super User

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;
n6
Quartz | Level 8 n6
Quartz | Level 8

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?

n6
Quartz | Level 8 n6
Quartz | Level 8

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.

PaigeMiller
Diamond | Level 26

@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?

--
Paige Miller
Quentin
Super User

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.

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
ballardw
Super User

@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;
n6
Quartz | Level 8 n6
Quartz | Level 8

That works beautifully.  Thanks.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 10 replies
  • 1453 views
  • 0 likes
  • 5 in conversation