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 (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.

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 (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.
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 (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.
smillard
Calcite | Level 5
That did it thanks! Used clusterwidth = 0.7

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1498 views
  • 3 likes
  • 2 in conversation