Data visualization with SAS programming

Boxplot Questions

Reply
New Contributor
Posts: 2

Boxplot Questions

Hello all. I am making some boxplots in SAS 9.2 and I have some very basic questions; I've only started working with SAS within the past couple weeks. Any help would be appreciated.

1. If I am using a skeletal plot, is it possible to change the orientation of the boxplots from vertical to horizontal?

2. How do you change the color of the boxplots?

3. How do you label the mean, median, and quartiles on the boxplot?

4. How do you change the labels for each class on the boxplot (i.e., if I have two boxplots and one is labeled DataA and the other is labeled DataB, how do I edit those names to something more descriptive)?

5. Is it possible to create a buffer around the plot so there's more than a hair's width of white space between the axis labels and the edge of the graphic?

Example code would be helpful. I'm pretty sure these are easy questions, but I'm just don't have a clue what I'm doing with SAS yet (!). Thanks.
SAS Super FREQ
Posts: 8,818

Re: Boxplot Questions

Hi:
Some questions:
1) What procedure are you using to create your boxplots? Can you show some of your code?

2) What is your destination of interest? (ODS HTML, ODS RTF, ODS PDF?) When you show your code, also show your ODS statements, if any and your STYLE= option (if any). Also, does your code have ODS GRAPHICS ON/ODS GRAPHICS OFF statements???

3) What is the purpose of the output (viewable in a web browser, editable in Microsoft Word or a word processor, printable from Adobe Acrobat Reader)? (#2 and #3 are related questions)

4) Have you searched the documentation for your procedure of interest? For example, if you are using PROC BOXPLOT, then examples can be found here:
http://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm#boxplot_toc.htm (There are examples of using PROC BOXPLOT in this documentation topic.)

Or, if you are using PROC SGPLOT, then you can find examples here:
http://support.sas.com/documentation/cdl/en/grstatproc/62603/HTML/default/viewer.htm#vbox-stmt.htm (VBOX)
http://support.sas.com/documentation/cdl/en/grstatproc/62603/HTML/default/viewer.htm#hbox-stmt.htm (HBOX)

cynthia
New Contributor
Posts: 2

Re: Boxplot Questions

Cynthia,

Thanks for your help. The purpose of the output is to put it on a PowerPoint slide for a presentation. Here is the code that I'm working with now:

data oneday;
input larvae $ precip @@;
datalines;
present 0.86 absent 1.24 absent 1.20 absent
[... lots more ...]
absent 0.71 absent 0.60
;
proc sort data=oneday; by larvae;
run;
title;
proc boxplot data=oneday;
plot precip*larvae / BOXSTYLE=Skeletal NOHLABEL;
label precip='Precipitation (in.)';
run;

Thanks again!
SAS Super FREQ
Posts: 8,818

Re: Boxplot Questions

Hi:
So, the the answer to question 1 is that you're using PROC BOXPLOT.

Let's go back to your original questions, then.
1. If I am using a skeletal plot, is it possible to change the orientation of the boxplots from vertical to horizontal?
I believe that you can ONLY generate horizontal box plots with PROC BOXPLOT if you use ODS GRAPHICS, as shown in this example:
http://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm#statug_boxplot_sect...
Since your code did not indicate that you were using ODS GRAPHICS, this means you would have to change your approach (from traditional BOXPLOT to BOXPLOT with ODS GRAPHICS). In addition to ODS GRAPHICS methods, you can also use PROC SGPLOT and the HBOX statement to generate horizontal box plots starting in SAS 9.2 version (as an alternative to PROC BOXPLOT.)

2. How do you change the color of the boxplots?
It depends. If you are using PROC BOXPLOT -without ODS GRAPHICS- then use options on the PLOT statement (as described in the documentation which shows various labelling and coloring options (such as CBOXFILL):
http://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm#statug_boxplot_sect...

If you are using ODS GRAPHICS ON/OFF, then you should read this section of the documentation:
http://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm#statug_boxplot_sect...
or this previous forum posting about changing colors with a style template if you are using ODS GRAPHICS:
http://support.sas.com/forums/thread.jspa?messageID=22858奊


3. How do you label the mean, median, and quartiles on the boxplot?
Again, consulting the documentation should help. For example, to label the mean, use the ALLLABEL= option. To show an inset box for other statistics, look at the INSET and the INSETGROUP statements.

4. How do you change the labels for each class on the boxplot (i.e., if I have two boxplots and one is labeled DataA and the other is labeled DataB, how do I edit those names to something more descriptive)?
Are you using BY group processing? Do you mean the names of the BY variables or do you mean the values of the variables along the X or Y axis??? Not sure what you mean here by the labels for each CLASS since PROC BOXPLOT does not allow for a CLASS statement. Have you tried changing the variable label or the variable format?

5. Is it possible to create a buffer around the plot so there's more than a hair's width of white space between the axis labels and the edge of the graphic?
Again, don't know what you mean by this -- whether I use the LISTING destination, ODS RTF or ODS HTML, there appears to be adequate space (more than a hair's width) between the axis label and the edge of the graph.

About PowerPoint...SAS does not have a direct interface to PowerPoint (your answer to my question #3) unless you are using the SAS Platform for Enterprise Intelligence (otherwise known as the BI Platform). So, in order to get your image into PowerPoint, you will either have to:
a) create an external image using SAS/GRAPH GOPTIONS and statements or
b) create an external PNG image file using ODS HTML and paste the created image into PowerPoint (and ignore the HTML file) or
c) create an ODS RTF file, which will have an embedded image and then cut and paste the embedded image from Word (when you open the RTF file) into PowerPoint or
d) use the BI Platform's SAS Add-in to Microsoft Office

Since you did not say (for #2) what your destination of choice is, I am going to assume it will either be ODS HTML or ODS RTF (since there is no direct interface to PowerPoint and you did not say whether you were using the SAS Add-in to Microsoft Office).

If you experiment with the TIMES data from this example:
http://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm#statug_boxplot_sect...

...then you could run many of the BOXPLOT examples from the documentation and experiment with the options for changing the output.

cynthia
[pre]
** Creating LISTING output to preview output;
ods listing style=listing sge=off;
title '1) Analysis of Airline Departure Delays';
title2 'BOXSTYLE=SKELETAL';
proc boxplot data=Times;
plot Delay*Day /
boxstyle = skeletal
alllabel=value
nohlabel cboxfill=pink name='boxlist';
insetgroup min q1 q2 mean q3 max/ header='Statistics';
label Delay = 'Delay in Minutes';
run;
ods listing close;

** Using ODS without ODS GRAPHICS;
ods rtf file='c:\temp\boxplot_noodsgraf.rtf';
ods html path='c:\temp' (url=none)
file='boxplot_noodsgraf.html' style=analysis;

title '2) Analysis of Airline Departure Delays';
title2 'BOXSTYLE=SKELETAL';
proc boxplot data=Times;
plot Delay*Day /
boxstyle = skeletal
alllabel=value
nohlabel cboxfill=pink name='simplods';
insetgroup min q1 q2 mean q3 max/ header='Statistics';
label Delay = 'Delay in Minutes';
format day mmddyy5.;
run;

ods _all_ close;
[/pre]
Contributor sfo
Contributor
Posts: 66

Re: Boxplot Questions

Hello,

I am creating a box plot which has two groups 0 and 1. But when I define the haxis by giving the axis option like axis2 label = (f=arial h=1 'Group'), my boxplot displays 3 values on xaxis 0, 0.5 and 1. If I don't define the haxis then the plot displays the correct values i.e. just 0 and 1. I am not sure why it is displaying the middle value 0.5 when I define the axis. Can you please guide me?

Thanks.

SAS Employee
Posts: 980

Re: Boxplot Questions

It would be useful to see your exact code & data.

But in general, to prevent procs from "bucketing" your data different ways, you can usually avoid that by making the values character rather than numeric (for example a character '0' and '1').

Contributor sfo
Contributor
Posts: 66

Re: Boxplot Questions

Thanks Robert. I used order option while defining the xaxis and it worked.

I have another question though. Is there a way to define two different titles when plotting box plot in the following way:

proc boxplot data=summary;

plot (weight length width)*day;

run;

i.e. I want different title for different plots that are produced when using the above way.

Thanks.

Super User
Posts: 11,114

Re: Boxplot Questions

Your axis2 definition might be needing an ORDER= (0 1) to control the values displayed on the axis.

Contributor sfo
Contributor
Posts: 66

Re: Boxplot Questions

It is working with order option. Thanks

But do you also know how to resolve the other q I asked:


Is there a way to define two different titles when plotting box plot in the following way:

proc boxplot data=summary;

plot (weight length width)*day;

run;

i.e. I want different title for different plots that are produced when using the above way.

Ask a Question
Discussion stats
  • 8 replies
  • 878 views
  • 0 likes
  • 5 in conversation