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?
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;
/*
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;
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.
Type=DISCRETE unfortunately didn't work. I wish the jitter would look like proc sgpanel:
Where would the style statement be under? Example code would be appreciated. Thank you.
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;
@orchid_sugar wrote:
Type=DISCRETE unfortunately didn't work. I wish the jitter would look like proc sgpanel:
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.
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;
I really like the image you posted, but the code didn't work for me:
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:
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;
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.
/*
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;
This blog post might help:
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 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: