Hi,
I am trying to use proc sgplot with the vbox and scatter statements to create an overlaid graph. I have seven groups ("grp") and three timepoints ("day"), with timepoint to be plotted on the x-axis and the plots to be split by group. I am using the following code:
proc sgplot data=data.sample;
vbox aval /
group = grp
category = day
nooutliers;
scatter x=day y=aval /
group = grp
groupdisplay = cluster
jitter;
run;
The plot itself is generating as expected. However, as you can see in the adjacent image, the offset from the x-axis timepoint ticks for each group is not aligned for the scatter plot clusters and the box plots. Why is this happening and how do I fix it? I would like the layout to be in the same format for all groups as it currently is for Group 4 (i.e., scatter plot cluster directly on top of box plot).
NB: I know the graph looks a bit weird and smushed in this format, it's made using dummy data. The distribution with the real data will be much cleaner.
I'm using Enterprise Guide version 8.3.3.181. A dummy dataset is attached.
Thanks in advance!
Sorry, maybe try adding groupdisplay=cluster and specifying clusterwidth in both plots:
groupdisplay = cluster
clusterwidth=.5
It looks like that should do it. You might want to play with the value. My guess is the vbox might have a different default clusterwidth than scatter.
And if I'm wrong again, then check out this blog post by graphing guru Sanjay Matange. It has a nice example of boxplot overlayed with scatter plot, with groups. https://blogs.sas.com/content/graphicallyspeaking/2015/12/23/box-plot-with-stat-table-and-markers/
Try removing groupdisplay=cluster from the scatter plot. I don't think you need it, and I think the clustering is causing your problem.
Or if you want the clustering, than try adding groupdisplay=cluster to the vbox. That should work too.
So basically you want both plots clustered or neither clustered.
Thanks Quentin, have just tried both options and sadly they didn't fix it. Removing the groupdisplay=cluster from the scatter statement causes all points to display in one line at each day, and adding it to the vbox statement didn't change the layout from the original code.
Sorry, maybe try adding groupdisplay=cluster and specifying clusterwidth in both plots:
groupdisplay = cluster
clusterwidth=.5
It looks like that should do it. You might want to play with the value. My guess is the vbox might have a different default clusterwidth than scatter.
And if I'm wrong again, then check out this blog post by graphing guru Sanjay Matange. It has a nice example of boxplot overlayed with scatter plot, with groups. https://blogs.sas.com/content/graphicallyspeaking/2015/12/23/box-plot-with-stat-table-and-markers/
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.