Hi SAS users,
I have constructed a boxplot graph with a lattice layout and a break at a specific location of the Y AXES. I was trying to add the n for the comparison groups to the bottom row by using innermargins. However when I add the innermargin the Y axis break changes location and disrupt the graph. What can I do to preserve the break at the right spot?
proc template;
define statgraph BrokenAxis;
begingraph;
layout lattice / rows=2 rowweights= (.5 .5)columns=1;
rowaxes;
rowaxis / griddisplay= on display = (ticks tickvalues line);
rowaxis / griddisplay= on display = (ticks tickvalues line);
endrowaxes;
entrytitle 'Unadjusted';
/*define row 1 */
layout overlay / xaxisopts= (display= (line))
yaxisopts=(display=(ticks tickvalues label)label="Cost ($)" griddisplay=on
linearopts=(includeranges=(min-120000 330000-max)
tickvaluelist=(20000 40000 60000 80000 100000 330000)));
boxplot x=&GRP y= ACT_TOTAL_COSTad /
meanattrs = (SYMBOL = DIAMOND weight=bold ) group=&XVAR groupdisplay=cluster
medianattrs= (thickness = 2);
endlayout;
/*define row 2 */
layout overlay /xaxisopts=( display=(ticks tickvalues line) type=discrete
discreteopts =(tickvaluefitpolicy=extractalways ) )
yaxisopts=(display=(ticks tickvalues label)label="poLOS (days)" griddisplay=on
linearopts=(includeranges=(min-30 95-max)
tickvaluelist=(5 10 15 20 25 95)));
boxplot x= &GRP y= postopLOS / meanattrs = (SYMBOL = DIAMOND weight=bold ) group= &XVAR groupdisplay=cluster
medianattrs= (thickness = 2)name ="L" ;
discretelegend "L" /border=true AUTOALIGN = (BOTTOM) LOCATION=OUTSIDE ;
innermargin / align=bottom separator=true;
axistable x =&GRP value = np /class=&XVAR colorgroup=&XVAR
valueattrs=(size=7) labelattrs=(size=7);
endinnermargin;
endlayout;
endlayout;
endgraph;
end;
run;
proc sgrender data= combined1 template= BrokenAxis;
format DM DM. ACT_TOTAL_COSTad cost_D comma7.;
run;
Absolutely! Go to the link below and click on the "Free Software" button. The web pages will take you through the steps.
https://www.sas.com/en_us/software/university-edition.html
Thanks!
Dan
Since we don't have your data, try these two things and see if it makes any difference:
1. Remove the ROWAXES block. Since your ROWDATARANGE is DATA by default, they should have no effect -- but let's see.
2. On your AXISTABLE, set CLASSDISPLAY=CLUSTER, which will position your axis table values under the box, taking up less vertical space.
Please post back with your results.
Thanks!
Dan
Hi Dan,
Thank you for your suggestions. The result is still messy though: not all the N are displayed, only the first row (blue). The break was raised a little but the outliers shown above the break at 95, in reality should be below it. Any other idea?
Thank you
Giampaolo
Hi Dan,
I am sorry I just realized that I did not implement your suggestion to include CLASSDISPLAY=CLUSTER.
For some reason the command is ignored and I cannot manage to overcome the below message:
CLASSDISPLAY=CLUSTER ------------ 1 WARNING 1-322: Assuming the symbol CLASS was misspelled as CLASSDISPLAY.
What version of SAS are you using?
Which maintenance level? The easiest way to get that information is to run the following code;
%put &sysvlong;
Thanks!
Dan
10959 %put &sysvlong; 9.04.01M1P120413
We did some testing here, and found this particular issue was fixed at SAS 9.4m3 (maintenance 3). You are currently running maintenance 1. Also, the CLASSDISPLAY option I suggested was added in maintenance 2. Do you have access to a maintenance 3 or greater installation?
If you download the latest University Edition, you should be able to do this graph without any problem.
Absolutely! Go to the link below and click on the "Free Software" button. The web pages will take you through the steps.
https://www.sas.com/en_us/software/university-edition.html
Thanks!
Dan
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.