11-03-2016 01:58 PM
I'm making a lot of box plots (270) and sending them to an .rtf file. However, the default is to put one graph per page, which takes up far too much room. Ideally, I'd like to be able to control the number and layout of graphs per page--for example, "3 rows and 4 columns" or "4 rows and 5 columns", etc. so that I can get fewer pages. Does anyone know of a way to do this?
Here is my macro which creates a single (jittered) box plot:
%macro box_plots (variable_title=, variable=);
define statgraph &variable.;
entryTitle "Serum Samples: &variable_title. by &phenotype_title.";
layout overlay / xaxisopts=(display=(tickvalues)
linearOpts=(tickvalueSequence=(start=1 increment=1 end=&num_of_groups.)
scatterPlot x=eval(0.08*rannor(569154)+group_n) y=&variable. /
markerAttrs=(symbol=circle) group=group_n datalabel=&variable._lab
boxplot x=group_n y=&variable. / display=(caps mean median)
proc sgrender template=&variable. data=&variable.;
And here is my code which outputs the graphs to an RTF file:
ods rtf file="O:\Path\3b All Analytes by Exposure and Sex Box Plots &sysdate. ZA.rtf";
/*269 more iterations of this macro with different variables*/
ods rtf close;
11-03-2016 02:33 PM
My first thought would be to look at SGPANEL and appropriate panel by statement / variables added to your data if needed. Group like topics and use specified numbers of columns and rows. The HBOX or VBOX will do box plots with different oreintation.
11-03-2016 02:50 PM
I agree with ballardw. I addition, if you do not have any natural grouping variables in your data, you can make up an indexing variable (1, 2, 3, etc.) for the data you want in each cell. Starting in SAS 9.4, we added a NOHEADER option on the PANELBY statement to turn off the cell headers. For this case, you can use the option to supress the display of the indexing variable, which has no meaning, while giving you control over your grid layout.
Hope this helps!
11-03-2016 02:58 PM
Thank you for the feedback! Unfortunately, I don't think SGPANEL will help here because I have to use a graph template since I'm doing jittered box plots, and I'm not sure how to use panels for this kind of graph. Additionally, all of the 270 variables are on wildly different scales which I think is a problem for SGPANEL (and it isn't convenient to look for variables with similar enough scales to group together). Unless you know of a solution to these dilemmas?
11-03-2016 03:07 PM
For SAS 9.4, Jittering support was added to the SCATTER statement in SGPLOT and SGPANEL, as was the ability to overlay the SCATTERs and BOXPLOTs. However, if your box plots are not in comparitive ranges, then SGPANEL will not work well for you. There are ways to make only one axis uniform and not the other, but that requires a layout of either one column or one row to be most effective.
On a side note, if you generate PDF instead of RTF, you could use ODS LAYOUT to do exactly what you want. Is that format possible for you?