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;
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;
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.
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;
is there any way to overlay jitter scatter plot on boxplot along with ViolinPlot
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/
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
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.
Thank you very much.
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!
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.
Ready to level-up your skills? Choose your own adventure.