Data visualization with SAS programming

Overlaying on a Boxplot

Reply
N/A
Posts: 0

Overlaying on a Boxplot

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).
N/A
Posts: 0

Re: Overlaying on a Boxplot

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.....
SAS Super FREQ
Posts: 864

Re: Overlaying on a Boxplot

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]
N/A
Posts: 0

Re: Overlaying on a Boxplot

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!
N/A
Posts: 0

Re: Overlaying on a Boxplot

not totally understand. But packed away..

Thanks! try to learn it.
SAS Super FREQ
Posts: 864

Re: Overlaying on a Boxplot

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
N/A
Posts: 0

Re: Overlaying on a Boxplot

Any chance that I can remove the whisker lines (and how)?

Thanks!
SAS Super FREQ
Posts: 864

Re: Overlaying on a Boxplot

Try this and see if it works for you:

whiskerattrs=(thickness=0)

Thanks!
Dan
N/A
Posts: 0

Re: Overlaying on a Boxplot

You're awesome!

Thanks!
SAS Super FREQ
Posts: 864

Re: Overlaying on a Boxplot

Actually, I think if you remove "caps" from your display list, you'll get the same effect.

Thanks!
Dan
N/A
Posts: 0

Re: Overlaying on a Boxplot

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.
SAS Super FREQ
Posts: 864

Re: Overlaying on a Boxplot

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
N/A
Posts: 0

Re: Overlaying on a Boxplot

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!
SAS Super FREQ
Posts: 864

Re: Overlaying on a Boxplot

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
N/A
Posts: 0

Re: Overlaying on a Boxplot

I appreciate your support very much. Thanks!
Post a Question
Discussion Stats
  • 15 replies
  • 1906 views
  • 0 likes
  • 3 in conversation