BookmarkSubscribeRSS Feed
Jennys
Calcite | Level 5
Hi
Anybody know if there is a way to get the boxes in a grouped boxplot above eachother instead of grouped? For example I plot salary per state and gender and I want salary on the y-axis and state on the x and one box per gender. On the x-axis i only want the state once, not twice as it is in this plot:

data kon;
length gender salary 8 state $15;
input gender salary state;
cards;
1 10000 Mora
1 15300 Stockholm
1 11500 Sala
1 12300 Gävle
1 11300 Mora
2 16800 Gävle
2 12500 Stockholm
2 13500 Norrköping
2 16200 Norrköping
2 17500 Sala
2 11700 Stockholm
2 17100 Mora

;
run;

data kon;
set kon;
do i = 1 to 100;
salary = salary+(i);
output;
end;
run;




ods graphics on;
proc sort data=kon;
by gender;
run;
proc boxplot data=kon;
plot salary*state (gender) /
boxstyle = schematic
horizontal
;

run;
ods graphics off;

thanks in advance
10 REPLIES 10
ChrisNZ
Tourmaline | Level 20
You mean like so:
[pre]
proc sort data=kon;
by state;
run;

axis1 order=10000 to 25000 by 5000;
axis2 order=('Gävle' 'Mora' 'Norrköping' 'Sala' 'Stockholm') ;

proc boxplot data=kon;
where gender=1;
plot salary*state /name='A' vaxis=axis1 haxis=axis2 cboxes=red;
run;
proc boxplot data=kon;
where gender=2;
plot salary*state /name='B' vaxis=axis1 haxis=axis2 cboxes=blue;
run;

ods graphics on;
goptions gaccess='sasgastd > nul';
proc greplay igout=work.gseg tc=sashelp.templt nofs;
template=whole;
treplay 1:A
1:B name='C' ;
quit;
ods graphics off;
Jennys
Calcite | Level 5
Thank you, chris.

Almost like that, I want the boxes to be horizontal, though. I tried to put the ods graphics above the first boxplot and the horizontal option, but it seem that greplay doesn´t use that result.

Br
Jenny
ChrisNZ
Tourmaline | Level 20
>it seem that greplay doesn´t use that result.

Make sure the GSEG catalog is empty when you generate your A and B graphs, otherwise, the new trials will be called A1, etc, and greplay wil always pick up the first versions.
Jennys
Calcite | Level 5
ODS graphics creates *.png files and no gseg catalog, so I wonder how thoose graphs can be used by proc greplay?

Since I need to make a horizontal box plot, I have to include the proc boxplot in the ods graphics statement. Like this:

ods graphics on;
proc boxplot data=kon;
where gender=1;
plot salary*state /horizontal name='A' vaxis=axis1 haxis=axis2 cboxes=red;
run;
proc boxplot data=kon;
where gender=2;
plot salary*state / horizontal name='B' vaxis=axis1 haxis=axis2 cboxes=blue;
run;


goptions gaccess='sasgastd > nul';
proc greplay igout=work.gseg tc=sashelp.templt nofs;
template=whole;
treplay 1:A
1:B name='C' ;
quit;
ods graphics off;
ChrisNZ
Tourmaline | Level 20
>ODS graphics creates *.png files and no gseg catalog, so I wonder how thoose graphs can be used by proc greplay?

There is a gseg catalog. Look in your work library.
Jennys
Calcite | Level 5
Did you run the code above, with the ods graphics on before the first boxplot? Because,there is no gseg catalog in the work. If you ran it, did it produce a horizontal boxplot and also the last one with greplay? Doesn't work for me.

Can you email me the results, so that I can see? jenny.soderberg@yahoo.com
br
Jenny
ChrisNZ
Tourmaline | Level 20
Hi Jenny,

I can't fathom why greplay works fine for vertical boxes and would behave differently for horizontal ones. Greplay just replays graphics, you could be drawing kittens for all it cares. Sorry I can not test with horizontal boxes as I don't have 9.2.

If you get stuck, there other ways, like using the rotate function of greplay's templates (you'll have to manually tweak the axis labels and values), or better yet, using Michael Friendly's powerful macro at http://www.math.yorku.ca/SCS/sssg/boxplot.html.
NicolaD
Calcite | Level 5
Hi Jenny,

I have managed to get exactly what I want using proc template and proc sgrender, thanks to some suggestions from SAS guys on here. I can now get overlaid horizontal boxplots as one of the boxplot options in proc template is orient= which specifies the orientation of the y-axis and the boxes so if you set it to horizontal you get hoizontal box plots, and when you set the layout=overlay you get overlaid horizontal boxplots. In proc template there is a whole load of attributes you can set too to change the appareance of the text, data markers, lables colours borders etc. I found it perfect for what I wanted to do.

This might be a useful resource if you're still struggling
http://support.sas.com/documentation/cdl/en/grstatgraph/63878/HTML/default/viewer.htm#/documentation...
NicolaD
Calcite | Level 5
Jenny, I've been following this thread as I've been trying to achieve something similar to you. I want horizontal boxplots on the same axis for different groups of data. I've been playing with your code and code suggested by Chris and can't get it to work either. I too have no gseg catalogue in Work. I think this is because when we put the proc boxplot statements inside the ODS graphics statements the plots are produced in ODS graphics output and rather than in a graphics catalgue and hence no gseg is produced. But we need to use ODS graphics to get horizontal plots. I haven't found a way round this yet and wondered if you had? of if anyone else has any suggestions we could try?

Nicola

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 10 replies
  • 1172 views
  • 0 likes
  • 3 in conversation