Hello,
I am relatively new to graphing in SAS, but am finding it great to have the level of control it provides. I have succeeded in making a box and whisker plot that meets all my specifications, but one. I have 8 groups (4 classes of each of two groups). I want the boxes of one group to be red, the other to be blue. Group 1 is values 1.0, 2.0, etc. Group 2 is 1.3, 2.3 etc. I want group 1 to be red, group 2 to be blue. I have searched, but have not seen a way to change color of individual boxes. I'm sure there is a more elegant way to do what I want, but would appreciate knowing how to control color of individual box and whisker displays, given the code I have thus far.
Thank you.
data temp;
set grant.ayp2010w2009_2;
label ma_rg_ach_level_mb09 = "Math 2009 Achievement Level"
new_abc_math_g = "Math 2010 Growth";
if grade = '04' or grade = '05';
if ma_rg_ach_level_mb09 = 'NULL' then ma_rg_ach_level_mb09 = ' ';
if ma_rg_ach_level_mb09 = 1 and SWD = 'N' then group = 1.0;
if ma_rg_ach_level_mb09 = 1 and SWD = 'Y' then group = 1.3;
if ma_rg_ach_level_mb09 = 2 and SWD = 'N' then group = 2.0;
if ma_rg_ach_level_mb09 = 2 and SWD = 'Y' then group = 2.3;
if ma_rg_ach_level_mb09 = 3 and SWD = 'N' then group = 3.0;
if ma_rg_ach_level_mb09 = 3 and SWD = 'Y' then group = 3.3;
if ma_rg_ach_level_mb09 = 4 and SWD = 'N' then group = 4.0;
if ma_rg_ach_level_mb09 = 4 and SWD = 'Y' then group = 4.3;
proc sort;
by group;
ods graphics on;
title ;
symbol
value = dot
height = 0.4
interpol = boxtf
width = 3
bwidth = 5
co = BL
cv = VLIGB
mode = include;
axis1
order = (-3, -2, -1, 0, 1, 2, 3)
label = (f= "Arial/Bold" height = 2.25 angle = 90 'Mathematics Growth Score 2010')
minor = (number = 1)
value = (f= "Arial" height = 1.75)
width = 2
color = black;
axis2
label = (f= "Arial/Bold" height = 2.25 'Math Proficiency Level 2009')
offset = (5, 5)
value = (f= "Arial" height = 1.75);
proc gplot data = temp
uniform ;
plot new_abc_math_g*group /
haxis = axis2
vaxis = axis1
hminor = 0
skipmiss ;
run;
quit;
You might try adding a variable for colorgroup or some such.
Then the plot statement becomes
plot new_abc_math_gr*group=colorgroup
And add a symbol2 statement with the color changes.
You might try adding a variable for colorgroup or some such.
Then the plot statement becomes
plot new_abc_math_gr*group=colorgroup
And add a symbol2 statement with the color changes.
Thank you, those changes did indeed produce two different colored box plots. Because both groups are represented in the four categories on the abscissa, the two sets of box plots sit right on top of one another with these changes. I need to offset them from the tick marks so one can see both sets of boxes. I am now playing with my options to get that done. I've tried switching to a numeric variable on the abscissa and changing values of two groups slightly (e.g., 1 becomes .8 for one group and 1.2 for the other group). I guess my other option is to overlay one graph on top of the other with an offset.
I'm not sure of your SAS version, but the boxplot you describe it simple to do with PROC SGPLOT. Try this example and see if it works for you:
proc sgplot data=sashelp.cars;
vbox mpg_city / category=origin group=type;
run;
I would try making more noticeable changes in the horizontal axis values and possibly adjust the AXIS statement to control tickmarks and such. Also you don't have a units specified for Width or Bwidth in the symbol statement. You may want to use a unit like bwidth=.2in or similar to get finer control of actual widths as the default is Cells which can be largish for some displays.
Registration is open! SAS is returning 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. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.