BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi,

I was wondering if a boxplot can be overlay be by another boxplot(s)?

I have three groups and two time points in my data and would like to get a graphical presentation on the change in measurement on each group. The measurement is on y-axis, time on x-axis with the three groups superimpose on each other. Ideally, the graph will have six bars; three on time-point 1 and three on time-point 2 with a median connection between bars for each group.

I am using PROC SGPLOT and VBOX statement to generate the boxplot but can't find the right options/ method to get the desire graph. My alternative approach was to using PROC SGPANEL with PANELBY (group) and VBOX statements, but that doesn't help to stack/ overlay the groups. Although the PROC BOXPLOT procedure has more options to customized the graph, but I was not sure (1) if I can overlay bars on a boxplot and (2) if that support ODS GRAPH function.

My best guess is to customized the graph in PROC TEMPLATE procedure, but I am not familiar on that and would like to get some help on that.

If someone could also let me know the code to remove the whisker and outliers on the boxplot, I would really appreciate it.

Thank you very much!

P.S.: My machine is running SAS v9.2 (TS2M2).
15 REPLIES 15
deleted_user
Not applicable
I am also not quite sure about this too.

normally, i do not use SAS to generate graphs for me. i copy the results to excel or other software that designed for graphs, which can let me adjust the graphs more freely...

actually, i have the similar question as yours.....
DanH_sas
SAS Super FREQ
Here is a simple GTL example of overlaid boxplots:

[pre]
proc template;
define statgraph boxplots;
begingraph;
layout overlay;
boxplot y=weight x=age / datatransparency=0.5 fillattrs=GraphData1
name="box1" legendlabel="Weight";
boxplot y=height x=age / datatransparency=0.5 fillattrs=GraphData2
name="box2" legendlabel="Height" yaxis=y2;
discreteLegend "box1" "box2";
endlayout;
endgraph;
end;
run;

proc sgrender data=sashelp.class template=boxplots; run;
[/pre]
deleted_user
Not applicable
Great thanks!!

One more question, I was trying to further modify the style and was not sure where/ how to add the following code:

style GraphBox / capstyle="Line" connect="Median" displayopts="Fill Caps Median Mean Outliers"

Thanks again!
deleted_user
Not applicable
not totally understand. But packed away..

Thanks! try to learn it.
DanH_sas
SAS Super FREQ
You can either put that information in the style or directly in your template. For example, if you put these three options on each of the boxplots, you'll get what you want:

capstyle=line connect=median display=(fill caps median mean outliers connect)

Thanks!
Dan
deleted_user
Not applicable
Any chance that I can remove the whisker lines (and how)?

Thanks!
DanH_sas
SAS Super FREQ
Try this and see if it works for you:

whiskerattrs=(thickness=0)

Thanks!
Dan
deleted_user
Not applicable
You're awesome!

Thanks!
DanH_sas
SAS Super FREQ
Actually, I think if you remove "caps" from your display list, you'll get the same effect.

Thanks!
Dan
deleted_user
Not applicable
Removing the "caps" doesn't help, but leaving the vertical lines on the graph.

The values of my box (Q1, median, Q3) range between 10 to 70 and I was trying to adjust the y-axis label by the following:

layout overlay / yaxisopts=(label="Outcome"
linearopts=(tickvaluesequence=(start=0 end=70 increment=10))) ;

There are some 80+ outlier values in my data which I don't want to show on the graph by removing the "outlier" in the display list.

Now the y-axis has the correct tick values, but it only occupies about half of the y-axis and leaving (upper) half of the graph area in blank.

Am I missing something?

Thanks.
DanH_sas
SAS Super FREQ
The way you are specifying your tick values allows the dataspace to include the data range of your outliers. That is your "blank" space. There are two options:

1. If you only want to see the extreme outliers, use LABELFAR=TRUE on the BOXPLOT statement.

2. If you want no outliers and do not want their data space, use VIEWMIN=0 and VIEWMAX=70 on the axisopts instead of the tick value sequence option.

Let me know if that works for you.

Thanks!
Dan
deleted_user
Not applicable
The viewmin and viewmax work perfect for me.

Is there a way to spread the bars a little bit to avoid overlap?

There is SPREAD= option for outliers, but was wondering if there is one for the bars?

Thanks!
DanH_sas
SAS Super FREQ
In the SAS v9.2m3, there is a way. However, to simulate that in v9.2TS2, you would need to use SGPANEL and make those previously mentioned box customizations in an ODS style.

Dan
deleted_user
Not applicable
I appreciate your support very much. Thanks!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 15 replies
  • 5354 views
  • 0 likes
  • 3 in conversation