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

How can I make jitter look more within boxplot area on proc sgplot?

I can see some data points are going into the other group.

Also, is there a way to change the color of boxplot to color blind friendly palette?

orchid_sugar_0-1694472241809.png

 

proc sgplot data=ratio_long;
	vbox ratio / category = x group = FacilityType
		whiskerattrs=(thickness=0)nooutliers nomean fillattrs=(transparency=0.7)
		medianattrs=(thickness=5);

	scatter x=x y=y/group=FacilityType groupdisplay=cluster jitter
		markerattrs=(symbol=CircleFilled size=4) transparency = 0.5;

	keylegend / title = 'Facility Type' position=bottom;
	yaxis grid values=(0 to 1.1 by 0.1);
	xaxis display=(nolabel);
	refline 1 / axis=y lineattrs=(pattern=shortdash color=green);
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
/*
As ballardw said,post your real data,so we can replicate your problem.
Also try "jitter=uniform" "jitterwidht=" option:
*/
proc sgplot data=sashelp.heart(obs=2000);
	vbox weight / category =Smoking_Status  group = BP_Status groupdisplay=cluster clusterwidth=0.8
		whiskerattrs=(thickness=0) nooutliers nomean fillattrs=(transparency=0.7)
		medianattrs=(thickness=5) name='x';

	scatter x=Smoking_Status y=weight/group=BP_Status groupdisplay=cluster clusterwidth=0.8 jitter=uniform jitterwidth=0.5
		markerattrs=(symbol=CircleFilled size=4) transparency = 0.5;

	keylegend 'x' / title = 'Facility Type' position=bottom;
	xaxis colorbands=odd;
run;

Ksharp_0-1694605059447.png

 

View solution in original post

10 REPLIES 10
DanH_sas
SAS Super FREQ

I don't have your data to try this, but what do you get if you add TYPE=DISCRETE to the XAXIS statement?  As for the style, try "illuminate" as a light-based style and see if works for you better. Also, try "Ignite" (dark-based) and "HighContrast" as alternatives.

orchid_sugar
Fluorite | Level 6

Type=DISCRETE unfortunately didn't work. I wish the jitter would look like proc sgpanel:

orchid_sugar_0-1694478842512.png

Where would the style statement be under? Example code would be appreciated. Thank you.

DanH_sas
SAS Super FREQ

Jittering should work similarly between SGPLOT and SGPANEL. Is there any difference in the data used between the two procedures? or in the variable specifications?

 

As for the style, use the STYLE option on the ODS destination, for example:

 

ods html style=illuminate;

ballardw
Super User

@orchid_sugar wrote:

Type=DISCRETE unfortunately didn't work. I wish the jitter would look like proc sgpanel:

orchid_sugar_0-1694478842512.png

Where would the style statement be under? Example code would be appreciated. Thank you.


If you want something closer to this then you should include the code used for this graph as well.

 

Have you tried the JITTERWIDTH= option?

Here is an example with a data set you should have so you can test this code. This is loosely similar to your graph as it is a grouped overlay of scatter over vbox but has a great many collisions in the the Y variable.

proc sgplot data=sashelp.heart;
  vbox cholesterol / category=weight_status group=sex;
  scatter x=weight_status y=systolic / group=sex
     groupdisplay=cluster jitter
    jitterwidth= 1.5;

run;

Run this. Then change the JITTERWIDTH= to 0.5   is that what you are requesting?

proc sgplot data=sashelp.heart;
  vbox cholesterol / category=weight_status group=sex;
  scatter x=weight_status y=systolic / group=sex
     groupdisplay=cluster jitter
    jitterwidth= 1.5;

run;

The default for Jitterwidth is 0.85. So any positive value  less than 0.85 will make the width of the scatter less, larger will be wider.

Ksharp
Super User
proc sgplot data=sashelp.heart(obs=2000);
	vbox weight / category =Smoking_Status  group = BP_Status groupdisplay=cluster clusterwidth=1
		whiskerattrs=(thickness=0) nooutliers nomean fillattrs=(transparency=0.7)
		medianattrs=(thickness=5) name='x';

	scatter x=Smoking_Status y=weight/group=BP_Status groupdisplay=cluster clusterwidth=1 jitter
		markerattrs=(symbol=CircleFilled size=4) transparency = 0.5;

	keylegend 'x' / title = 'Facility Type' position=bottom;
	xaxis colorbands=odd;
run;

Ksharp_0-1694518856568.png

 

orchid_sugar
Fluorite | Level 6

I really like the image you posted, but the code didn't work for me:

orchid_sugar_2-1694531108055.png

ods graphics on / width=10in height=5in;
proc sgplot data=ratio_long;
	vbox y / category = x group = FacilityType groupdisplay=cluster clusterwidth=1
		whiskerattrs=(thickness=0)nooutliers nomean fillattrs=(transparency=0.7)
		medianattrs=(thickness=5) name='x';

	scatter x=x y=y/group=FacilityType2019 groupdisplay=cluster clusterwidth=1 jitter
		markerattrs=(symbol=CircleFilled size=4) transparency = 0.5;

	keylegend 'x'/ title = 'Facility Type' position=bottom;
	yaxis grid values=(0 to 1.1 by 0.1);
	xaxis display=(nolabel) colorbands=odd;
	refline 1 / axis=y lineattrs=(pattern=shortdash color=green);
run;

Adjusting the jitterwidth helped but it is off center for some reason:

orchid_sugar_1-1694531084296.png

ods graphics on / width=10in height=5in;
proc sgplot data=ratio_long;
	vbox y / category = x group = FacilityType groupdisplay=cluster
		whiskerattrs=(thickness=0)nooutliers nomean fillattrs=(transparency=0.7)
		medianattrs=(thickness=5);

	scatter x=x y=y /group=FacilityType groupdisplay=cluster jitterwidth=0.2 jitter
		markerattrs=(symbol=CircleFilled size=4) transparency = 0.5;

	keylegend / title = 'Facility Type' position=bottom;
	yaxis grid values=(0 to 1.1 by 0.1);
	xaxis display=(nolabel); *colorbands=odd;
	refline 1 / axis=y lineattrs=(pattern=shortdash color=green);
run;
ballardw
Super User

Data certainly helps.

 

Is your X variable text or numeric?

 

I think your "off center" is the SCATTER group display= cluster and possibly CLUSTERWIDTH setting related compared with how VBOX separates boxes. Note that on the left side of the cluster, near the blue box, the Scatter points are offset to the left, in the middle for the green box pretty much centered and the right side with the pink(?) box the scatter is offset to the the left though is hard to see as there are very few "pink" points plotted at all.

orchid_sugar
Fluorite | Level 6
x is text and y is numeric
Ksharp
Super User
/*
As ballardw said,post your real data,so we can replicate your problem.
Also try "jitter=uniform" "jitterwidht=" option:
*/
proc sgplot data=sashelp.heart(obs=2000);
	vbox weight / category =Smoking_Status  group = BP_Status groupdisplay=cluster clusterwidth=0.8
		whiskerattrs=(thickness=0) nooutliers nomean fillattrs=(transparency=0.7)
		medianattrs=(thickness=5) name='x';

	scatter x=Smoking_Status y=weight/group=BP_Status groupdisplay=cluster clusterwidth=0.8 jitter=uniform jitterwidth=0.5
		markerattrs=(symbol=CircleFilled size=4) transparency = 0.5;

	keylegend 'x' / title = 'Facility Type' position=bottom;
	xaxis colorbands=odd;
run;

Ksharp_0-1694605059447.png

 

SAS Innovate 2025: Register Now

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!

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
  • 10 replies
  • 3162 views
  • 4 likes
  • 5 in conversation