- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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/
Next up: SAS Trivia Quiz hosted by SAS on Wednesday May 21.
Register now at https://www.basug.org/events.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Next up: SAS Trivia Quiz hosted by SAS on Wednesday May 21.
Register now at https://www.basug.org/events.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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/
Next up: SAS Trivia Quiz hosted by SAS on Wednesday May 21.
Register now at https://www.basug.org/events.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content