Hi SAS community
I'm a fairly experienced PROC SGPLOT user, so I hope I haven't missed something simple in the online documentation.
A few questions re sizing in PROC SGPLOT (not PROC GPLOT)
Is there any way to control any of the following:
1) Tick mark size (ie tick mark length)
2) The amount of vertical space between x-axis tick MARKS and tick VALUES
3) The amount of vertical space between x-axis tick VALUEs and x-axis label (label must be below the VALUEs, not to the left or right).
4) The amount of vertical space between the top of the y-axis and the y-axis label when using labelpos=top?
All of the sizes and spacings are fine when using a sensible chart size such as say 4in high x 6in wide.
But once you make the chart sizes smaller (don't ask me why you would - I just work here!) or larger these default sizes and spaces seem to remain constant, rather than proportional to chart size and they no longer look so good.
We are required to have standard font sizes, regardless of chart size, so the scale option is of no use.
I can quite easily annotate tick marks and labels on myself, but am hoping for a simpler solution for some of our less experienced SAS users.
I'm using SAS 9.4, maintenance release 3.
Thanks
There is no way to make the changes you are asking if you set SCALE=OFF. The scale option was put in place precisely to control these settings when the graph size is changed (especially reduced), to result in "nicer" values. However the font is also scaled.
Having said that, various sizes are factored by the ratio of graph heights. For fonts, the factor is (new graph height / default graph height) ** 0.25. Usually, defaul height is 480px. So, if you want the scaling of the gaps, but not for the fonts, you could set SCALE=ON and then scale up the font sizes by the reverse of this factor to keep fonts sizes constant .
So, for a graph height of 200 px, the font scale factor will be (200/480)**0.25 = 0.803. You can try setting the font sizes higher by 1/0.803=1.244 or about 25%. For LISTING style, value font is 9pt. You can try setting it to 12.5pt to get the same size as the original unscaled font. Gap factors are linear to the height scale, so they will still shrink. Try that to see if you get a better result. You will need to change all the font sizes, either in the syntax, or in the style.
ods graphics / reset width=6.4in height=4.8in imagename='Full'; title '11 pt font'; proc sgplot data=sashelp.class; scatter x=height y=weight; run; ods graphics / reset width=6.4in height=2in imagename='Small'; title h=14pt '11 pt font'; proc sgplot data=sashelp.class; scatter x=height y=weight; xaxis valueattrs=(size=11.2pt) labelattrs=(size=12.5pt); yaxis valueattrs=(size=11.2pt) labelattrs=(size=12.5pt); run;
There is no way to make the changes you are asking if you set SCALE=OFF. The scale option was put in place precisely to control these settings when the graph size is changed (especially reduced), to result in "nicer" values. However the font is also scaled.
Having said that, various sizes are factored by the ratio of graph heights. For fonts, the factor is (new graph height / default graph height) ** 0.25. Usually, defaul height is 480px. So, if you want the scaling of the gaps, but not for the fonts, you could set SCALE=ON and then scale up the font sizes by the reverse of this factor to keep fonts sizes constant .
So, for a graph height of 200 px, the font scale factor will be (200/480)**0.25 = 0.803. You can try setting the font sizes higher by 1/0.803=1.244 or about 25%. For LISTING style, value font is 9pt. You can try setting it to 12.5pt to get the same size as the original unscaled font. Gap factors are linear to the height scale, so they will still shrink. Try that to see if you get a better result. You will need to change all the font sizes, either in the syntax, or in the style.
ods graphics / reset width=6.4in height=4.8in imagename='Full'; title '11 pt font'; proc sgplot data=sashelp.class; scatter x=height y=weight; run; ods graphics / reset width=6.4in height=2in imagename='Small'; title h=14pt '11 pt font'; proc sgplot data=sashelp.class; scatter x=height y=weight; xaxis valueattrs=(size=11.2pt) labelattrs=(size=12.5pt); yaxis valueattrs=(size=11.2pt) labelattrs=(size=12.5pt); run;
Thanks Sanjay
Makes perfect sense: knowing that formulae really helps, and it has worked well for our purposes.
Note: The same formula also applies to marker size for scatter plot. Default marker size is 7px. You can use the font multiplier to scale up the marker too.
Good to know Sanjay, thanks again.
A related question (hopefully ok to pose here rather than a new post): compared to SAS/Graph, the amount of vertical white space between a top outside legend and the y-axis label (if using labelpos=top which we have to use) is quite large on standard sized graphs. (see attached).
I can see that the space would be useful if the legend was wide and extended to the left to be above the y-xis label. But in the attached, it does seem like qute a lot of space.
To meet our publication standards we tend to have to not have a y-axis label and annotate one on to reduce that large gap between the legend and the y-axis label.
Is there an option we are missing to reduce the amount of whitespace under the legend?
Thanks!
Yes. Use OUTERPAD=(BOTTOM=0) in the KEYLEGEND statement to remove all the bottom padding (outside the border). Note, the gap may look higher than expected when there are no descenders in the legend values.
Thanks again Sanjay.
The SAS documention implied the default was "no padding" so I had assumed there already was no bottom pad.
But you know what they say about assuming.
Your suggested code does indeed make a difference.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.