Is there any way to add minor tick marks on the vertical axis using PROC BOXPLOT? It seems like there is, per documentation and Google searches, but nothing I try works. I get the majors, of course, but no ticks in between.
I've tried this:
axis1 minor = (h = 0.4 number = 1) order = (-20 to 10 by 2) major = (h = 0.8);
proc boxplot data = ft2;
where avisitn = &QQ;
plot Change * Treatment / vaxis = axis1 nohlabel cboxes =(color) symbollegend = legend1;
legend1 label = (' ');
title1 h=8pt color=black font='courier' J=L "xxxxxxxx, Inc.";
title2 h=8pt color=black font='courier' J=L "&STDNO Page &PAGVAR of 4";
title5 h=8pt color=black font='courier' J=C "&TITLE5";
title6 h=8pt color=black font='courier' J=C "&TITLE6";
title7 h=8pt color=black font='courier' J=C "&TITLE7";
title9 h=8pt color=black font='courier' J=C "&VISTEXT";
run;
and this.
/*axis1 order = (-7 to 7.5 by 1) */;
proc boxplot data = ft2;
where avisitn = &QQ;
plot Change * Treatment / /*vaxis = axis1*/ vaxis=-7 to 7.5 by 1 vminor = 0.5 nohlabel;
legend1 label = (' ');
title1 h=8pt color=black font='courier' J=L "xxxxxxx, Inc.";
title2 h=8pt color=black font='courier' J=L "&STDNO Page &PAGVAR of 4";
title5 h=8pt color=black font='courier' J=C "&TITLE5";
title6 h=8pt color=black font='courier' J=C "&TITLE6";
title7 h=8pt color=black font='courier' J=C "&TITLE7";
title9 h=8pt color=black font='courier' J=C "&VISTEXT";
run;
Thanks in advance...
Hi @davehalltwp,
I do get minor tick marks with either approach (both in traditional SAS/GRAPH output and in HTML output). The only correction I had to make was vminor = 1 (or 2, 3, ... for more minor tick marks) in the second approach because VMINOR=n "specifies the number of minor tick marks between major tick marks" (documentation). Without the H= specification of the AXIS1 statement (i.e., with the second approach) the minor tick marks can be very short (like only one pixel), though, if traditional output is created in a window with portrait orientation. Are there any warnings in the log?
Hi @davehalltwp,
I do get minor tick marks with either approach (both in traditional SAS/GRAPH output and in HTML output). The only correction I had to make was vminor = 1 (or 2, 3, ... for more minor tick marks) in the second approach because VMINOR=n "specifies the number of minor tick marks between major tick marks" (documentation). Without the H= specification of the AXIS1 statement (i.e., with the second approach) the minor tick marks can be very short (like only one pixel), though, if traditional output is created in a window with portrait orientation. Are there any warnings in the log?
Thanks for taking a look. Yeah, you are right, of course, that my specification of "0.5" was bogus and it should have been "1".
There's nothing in the log out of the ordinary.
I am writing to a .rtf file, which they want. Maybe that's part of the problem.
I appreciate the ideas...
data ft2;
call streaminit(27182818);
length color $8;
do treatment=1, 2;
color=choosec(treatment,'red','green');
do _n_=1 to 50;
change=rand('uniform',-21,8)+treatment;
output;
end;
end;
run;
ods rtf file = "C:\Temp\boxplot.rtf";
goptions reset=all;
axis1 minor = (h = 0.4 number = 1) order = (-20 to 10 by 2) major = (h = 0.8);
proc boxplot data = ft2;
plot Change * Treatment / vaxis = axis1 nohlabel cboxes =(color) symbollegend = legend1;
legend1 label = (' ');
run;
ods rtf close;
With the self-contained program above -- using SAS 9.4M5 under Windows -- I created the RTF file boxplot.rtf (size: 13 KB). I opened it with Word 2013, zoomed in and took the partial screenshot below:
After reading through your message more slowly, I realized that I have always had a poor understanding of the "background" setup for SAS graphics. For instance, I don't really know what this really means: " (both in traditional SAS/GRAPH output and in HTML output)."
So based on that, on a whim, I made this change, and now I am getting the minor tick marks (as well as the different colors for each box that I was trying for earlier):
*ods graphics on / width = 8.5 in height =3.7 in; ** this controls the size of the plot **;
ods graphics off / width = 8.5 in height =3.7 in; ** this controls the size of the plot **;
I'm like a monkey in that I don't fully understand what I've done, but my plots are what I need now. So thank you very much, I truly appreciate it (and will mark your post as SOLUTION!)
When I have time I will try to further educate myself on these topics, because I've always enjoyed doing plots and figures but need to get stronger at this part of it.
...dave
You're welcome. Glad to read that the minor tick marks finally appeared.
@davehalltwp wrote:
(...) For instance, I don't really know what this really means: " (both in traditional SAS/GRAPH output and in HTML output)."
Sorry, I think my wording was a bit unclear. I meant the GRAPH window showing the boxplot from the (default) catalog WORK.GSEG (as in the old days before the advent of ODS) vs. the PNG file embedded in HTML output (after activating "Create HTML" in Tools --> Options --> Preferences). However, the latter can still be "traditional" SAS/GRAPH output if the checkbox "Use ODS Graphics" in the Preferences window is not ticked and ODS GRAPHICS is switched OFF.
@davehalltwp wrote:
So based on that, on a whim, I made this change, and now I am getting the minor tick marks (as well as the different colors for each box that I was trying for earlier):
*ods graphics on / width = 8.5 in height =3.7 in; ** this controls the size of the plot **; ods graphics off / width = 8.5 in height =3.7 in; ** this controls the size of the plot **;
Good idea to try and switch ODS GRAPHICS off. I have this statement in my autoexec file, so I tend to forget that it is not the default setting in most SAS installations.
SAS/GRAPH procedures such as PROC GPLOT always produce "traditional" (device-based) graphics. In contrast, the "modern" PROC SGPLOT and the other SG... procedures always produce (template-based) ODS graphics. But then there are procedures such as PROC BOXPLOT, PROC UNIVARIATE (with its HISTOGRAM statement) and several others which are capable of producing either type of graphics -- depending on whether ODS graphics is enabled (cf. this 2017 post). This is when confusion starts, e.g., if explicit color specifications are not honored (because they're overridden by ODS style templates), as it happened in your case.
I recently came across a link to an old post which explains the impact of ODS GRAPHICS and the GSTYLE system option on graphs produced by PROC UNIVARIATE.
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!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.