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

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;

 

 

test_figure.pngThe 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!

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

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/

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.

View solution in original post

4 REPLIES 4
Quentin
Super User

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.

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
smillard
Calcite | Level 5

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.

Quentin
Super User

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/

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
smillard
Calcite | Level 5
That did it thanks! Used clusterwidth = 0.7

SAS Innovate 2025: Register Today!

 

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.


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
  • 4 replies
  • 1750 views
  • 3 likes
  • 2 in conversation