BookmarkSubscribeRSS Feed

Using PROC SGPLOT to Produce Box Plots with Contrasting Colours in SAS

Started ‎04-09-2015 by
Modified ‎10-05-2015 by
Views 1,454

The following article was originally published on my blog, The Chemical Statistician.

 

I previously explained the statistics behind box plots and how to produce them in R in a very detailed tutorial.  I also illustrated how to produce side-by-side box plots with contrasting patterns in R.

Here is an example of how to make box plots in SAS using the VBOX statement in PROC SGPLOT.  I modified the built-in data set SASHELP.CLASS to generate one that suits my needs.

The PROC TEMPLATE statement specifies the contrasting colours to be used for different classes.  I also include code for exportingthe result into a PDF file using ODS PDF.  (I used varying shades of grey to allow the contrast to be shown when printed in black and white.)

boxplots

 

There are some very useful SAS documents on the different colours and marker symbols.  There is a separate documentation page colour schemes in SAS/GRAPH programs, and it has a specific section on grey-scale colour codes.

ods path(prepend)          

     work.template(update);

 

proc template;          

     define style mystyle;          

     parent = styles.printerl;

     class graphdata1

          /    color = grayaa                    

               contrastcolor = gray00                    

               markersymbol = 'circle';

     class graphdata2

          /    color = graycc                    

               contrastcolor = grayaa                    

               markersymbol = 'square';          

     end;

run;  

 

data heights;         

     set sashelp.class;          

     if age < 13                    

           then teenager = 'Pre-Teenager';

     else teenager = 'Teenager';

    

     if sex = 'F'                    

               then gender = 'Female';          

      else gender = 'Male';           

      label            gender = 'Gender'                              

                           teenager = 'Age Group';

     keep height gender teenager; run; 

 

 

 

ods pdf file = 'INSERT YOUR DIRECTORY PATH HERE\heights.pdf'          

     notoc style = mystyle;

 

 

proc sgplot          

     data = heights;          

     vbox height /                    

     category = gender                    

     group = teenager;

run;  

 

ods pdf close;

Version history
Last update:
‎10-05-2015 03:26 PM
Updated by:

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Labels
Article Tags