Using PROC SGPLOT to Produce Box Plots with Contrasting Colours in SAS
January 7, 2015 Leave a comment
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.
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.)
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.printer;
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;