BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mmzz
Calcite | Level 5

I want to add jitter scatter plot on my boxplot.  I used sgplot to produce my boxplot.  I found this post here http://blogs.sas.com/content/graphicallyspeaking/2012/05/07/unbox-your-box-plots/

The picture is exactly what I want but I wonder if I can produce it with sgplot.

 

Below is my sgplot code

 

proc sgplot data=box;
/* title "Plot of Hemoglobin A1c - baseline";*/
YAXIS label='Diastolic blood pressure' LABELATTRS=(SIZE= 8);
XAXIS label=' ' LABELATTRS=(SIZE= 8);
vbox result / datalabel=outid;
ods output SGPlot=boxlist;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

If you have SAS 9.4, maintenance 1 or greater, you can do it like this:

 

proc sgplot data=sashelp.cars;
vbox weight / category=type;
scatter x=type y=weight / jitter;
run;

SGPlot2.png

View solution in original post

8 REPLIES 8
ballardw
Super User

If you search your documentation for SGPLOT and SGPANEL for "Plot Type Compatibility" you will find that in those procedures the only plots that can be used together with VBOX are Density, HBOX and Histogram.

 

The nature of the plot determines which other types share the "plot space".

 

It may be possible with an annotate dataset with SGPLOT but no promises.

 

OR sumarize your data and possibly use Polygon and lineparm or such along with scatter to simulate the VBOX portion.

 

Reeza
Super User
Pretty sure this was asked and answered recently on here. Search through the forums. You may also be interested in the default plots from PROC UNIVARIATE, they do a good job of displaying the distribution of data.
DanH_sas
SAS Super FREQ

If you have SAS 9.4, maintenance 1 or greater, you can do it like this:

 

proc sgplot data=sashelp.cars;
vbox weight / category=type;
scatter x=type y=weight / jitter;
run;

SGPlot2.png

Nagadurga
Calcite | Level 5

is there any way to overlay jitter scatter plot on boxplot along with ViolinPlot

Jay54
Meteorite | Level 14

See this article in Graphically Speaking.  It is a bit old, and there may be easier ways to do this using SAS 9.4 or later.

https://blogs.sas.com/content/graphicallyspeaking/2012/10/30/violin-plots/

 

Nagadurga
Calcite | Level 5

Hello Sanjay,

 

I am trying to overlay a Boxplot, Scatterplot and ViolinPlot.For this I am using PROC SGPLOT with sas 94.

 

Example code is as below to produce boxplot + scatterplot.

However when one adds the bandplot to this, then it does not work anymore.

See the warning below obtained when adding a bandplot statement.

 

proc sgplot data=ars;

vbox rcbi / category=arm2 boxwidth=0.4 nooutliers;

scatter x=arm2 y=rcbi / group=arm2  jitter transparency=0.6

         markerattrs=(/*color=red*/ symbol=CircleFilled);

run;

 

WARNING: BANDPLOT statement has a conflict with the axis type. The plot will not be drawn.

 

This is the same when using proc SGPANEL.

I can create the violin plot using band statement using code below

 

proc sgpanel data=final;

panelby arm2;

band y=rcbi2 lower=mirror upper=density;

run;

 

But it does not work anymore if I add the vbox and scatter statement on top …

Let me know if any thoughts

 

Jay54
Meteorite | Level 14

You can overlay the Band and the Scatter without any issues.  Adding VBox is the issue.

 

Since all data markers are already in the plot (Scatter) you only need to overplot the Q1-Q3 box, Mean, Median and Whiskers.  One way to do this would be to first run PROC MEANS to get these values in an output data set.  Then merge these with the original data, and use HighLow plot(s) overlay to draw the box details along with the Scatter and Band.  Use another scatter for the Mean marker.  I suggest dimming (transparency) the scatter markers to avoid clutter.

smitham
Fluorite | Level 6

Thank you very much.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 17683 views
  • 5 likes
  • 7 in conversation