Data visualization with SAS programming

Plot multiple groups of boxes with decile lines

Reply
Frequent Contributor
Posts: 102

Plot multiple groups of boxes with decile lines

There does not seem to be a straightforward way to plot multiple box/bar groups with bars separated by decile lines. 

I have a dataset with several Measures and deciles for each measure.  Here's a simulated dataset:

data d;

  do Measure=1 to 5;

   do i=0 to 10;

     DecileVal = ranuni(0);

  output;

  end; end;

  drop i;

proc rank data=d out=d;

  by Measure;

  var DecileVal;

  ranks Decile;

proc sort data=d; by Measure Decile;

run;

So far the closest I get is this:

proc sgplot data=d;

  scatter x=Measure y=DecileVal / markerattrs=(symbol=plus);

run;

Still need:

- Change pluses into horizontal lines

- To add vertical boxes that start at a Min value and end at Max.

Can something like this be done in SGPlot?  I need to overlay odds ratios with CI over the bars?

Appreciate any help or pointers.

Frequent Contributor
Posts: 102

Re: Plot multiple groups of boxes with decile lines

Here's another SGPLOT routine that gives me something similar to what I am looking for but with estimated rather than literal percentiles, 50th, 25th, and 75th percentiles and whiskers at 0 and 100.

Grand Advisor
Posts: 9,748

Re: Plot multiple groups of boxes with decile lines

Maybe not with SGPlot but you may find something at http://support.sas.com/sassamples/graphgallery/PROC_SGRENDER_Graph_Template_Language__GTL_.html that looks close to what you want. There are links to code to create each of the examples.

Frequent Contributor
Posts: 102

Re: Plot multiple groups of boxes with decile lines

Thanks for the suggestion, Ballardw.  Nothing there that looks like what I want but a good resource. Also, have done very limited amount of programming in TEMPLATE.  Useful skill but a steep learning curve.

I ended up transposing the Tall file into a wide one and using the following code:

proc sgplot data=df noautolegend;

  highlow x=Outcome low=D1 high=D11 /type=bar;

  highlow x=Outcome low=D2 high=D10 /type=bar;

  highlow x=Outcome low=D3 high=D9  /type=bar;

  highlow x=Outcome low=D4 high=D8  /type=bar;

  highlow x=Outcome low=D5 high=D7  /type=bar;

  highlow x=Outcome low=D6 high=D6  /type=bar;

  scatter x=Outcome y=OR / markerattrs=(color=black symbol=DiamondFilled size=15)

  yerrorlower=Lower yerrorupper=Upper errorbarattrs=(color=black thickness=2);

  xaxis labelattrs=(weight=bold size=14);

  yaxis label='Odds Ratio (95% CI)' labelattrs=(weight=bold size=14);

run;

Any feedback or suggestions for improvement is greatly appreciated.

SAS Super FREQ
Posts: 1,044

Re: Plot multiple groups of boxes with decile lines

You can overlay SCATTERPLOT on BOXPLOT using GTL. 

And yes, you can use a combination of HIGHLOW plots to simulate a box plot as I discuss in this blog post.  http://blogs.sas.com/content/graphicallyspeaking/2013/03/24/custom-box-plots/

Post a Question
Discussion Stats
  • 4 replies
  • 483 views
  • 3 likes
  • 3 in conversation