Data visualization with SAS programming

Boxplot grouping

Reply
Contributor GDA
Contributor
Posts: 21

Boxplot grouping

Hi all

I am trying to create what I believe to be a relatively simple set of boxplots. I want to be able to group the x-axis by certain variables. Then the legend should show the differences.

For example.

I am plotting the "number of errors" on the y-axis vs 2 variables on the x. First one being "Test_Time_bin" and second being "Substrate" The number of values for both Test_Time and Substrate will change for every dataset I am going to plot so I cannot hard code anything. For each value of "Test_Time_Bin" I want multiple boxplots (side by side) for each value of "Substrate".

I have searched around and haven't had any luck with finding example code. I did find a picture of the exact thing I want to do for reference. Figure 2 at this link:

http://www.information-management.com/issues/20050801/1033566-1.html

Hope I am explaining enough here.

thanks
SAS Employee
Posts: 980

Re: Boxplot grouping

With traditional SAS/Graph "proc gchart", you can do grouped bar charts, and turn on the 'errorbar' on each bar, and get something a little bit similar (not exactly what you're wanting though). For example:

axis1 value=(angle=90);
pattern1 v=s c=yellow;

proc gchart data=sashelp.revhub2;
vbar type / type=mean sumvar=revenue errorbar=both
group=hub space=0 gspace=5 maxis=axis1;
run;

To get something more like the graph in your link, you'd have to pre-calculate everything, and then put together a special data set to do a grouped bar, with a "floating" bar segment for the yellow part (by 'floating', I mean the lower of the 2 segments would be the same color as the background, making it 'invisible', such as ... http://robslink.com/SAS/democd6/col8.htm ). And then annotate the box plot onto each of the bars (you'd need to pre-calculate the y-value for each of the pieces of the boxplot to use to construct your box plot: mean, lower, upper, etc). It would be a bit "cumbersome" Smiley Happy

Maybe/hopefully one of the new ODS Graphics procs provides an easier solution(?) Smiley Happy
SAS Super FREQ
Posts: 925

Re: Boxplot grouping

If you are running SAS 9.2, try something like the code below to see if this is what you want:

proc sgpanel data=your_data;
panelby test_time_bin / layout=columnlattice noborder onepanel;
vbox your_subval_variable / category=Substrate;
run;

There are other ways to tweak this example, but let me know if this the general form of what you want.

Thanks!
Dan
Contributor GDA
Contributor
Posts: 21

Re: Boxplot grouping

Thanks Fellas!

I don't like the idea of having to jump through too many hoops to get at what I want so I'm going to explore the SGPANEL solution, which is very close to what I want.

After I plugged in my data set, I would like 2 additional changes (if possible). #1 is kind of a show stopper and number 2 is just a nicety.

1. I need the panelby variable (test_time_bin) to display only the values on the graph. It is currently combining the variable name + the value. For example I need it to be "a. 0-100 hrs" instead of "Test_Time_Bin = a. 0-100 hrs", etc..... The data actually gets cut off unless I create a huuuuuuuuuuge graph, which I don't want to do.

2. I would like to get this entire group of panelby groups to the bottom of the graph instead of the top.

Boy I sure wish this forum would accept pictures so I could clearly explain what I'm looking for. Let me know if you need more info.

here's the code so far.

ods graphics / reset width=1200px height=700px MAXLEGENDAREA=50 IMAGEMAP=On;
ods html file='test.html' path="C:\" style=Festival;
title "Test Boxplots";

proc sgpanel data=WORK.BER_Deltas_with_Attributes ;
panelby test_time_bin / layout=columnlattice noborder onepanel;
vbox Num_Soft_Errs_delta / category=SBR_c;
run;

ods html close;
SAS Super FREQ
Posts: 925

Re: Boxplot grouping

1. Use the NOVARNAME option on the PANELBY statement.

2. Use the COLHEADERPOS=BOTTOM option on the PANELBY statement.

Thanks!
Dan
Ask a Question
Discussion stats
  • 4 replies
  • 250 views
  • 0 likes
  • 3 in conversation