Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Programming
- /
- Graphics
- /
- Overlaying on a Boxplot

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 06-02-2010 04:54 PM
(3964 views)

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).

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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.....

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.....

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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]

[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]

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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!

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!

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

not totally understand. But packed away..

Thanks! try to learn it.

Thanks! try to learn it.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

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

Thanks!

Dan

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

Thanks!

Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Try this and see if it works for you:

whiskerattrs=(thickness=0)

Thanks!

Dan

whiskerattrs=(thickness=0)

Thanks!

Dan

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

You're awesome!

Thanks!

Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

Thanks!

Dan

Thanks!

Dan

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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.

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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!

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!

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

Dan

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I appreciate your support very much. Thanks!

SAS is headed **back** to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team.

**Interested in speaking?** Content from our attendees is one of the reasons that makes SAS Innovate such a special event!

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.