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

Hi,

 

I am currently have code to plot data points that are visually represented based on the value of the "Outlier" variable using the MARKERCHAR option, which has values "A" or "B" (points show up as A or B on the plot). I have recently run into a situation where there are multiple points that have the same values, and they only show up as one point. I tried using the JITTER option, but it does not seem to work with MARKERCHAR. If I remove the MARKERCHAR option, JITTER works fine, and the multiple points are shown. Is there any workaround to have both options work? My code is below. Thanks!

PROC SGPLOT DATA = Data_Outliers  DESCRIPTION = "Scatter Box Plot" NOAUTOLEGEND ;
VBOX Value / CATEGORY=An_Run MEANATTRS=(SIZE=0) NOOUTLIERS FILLATTRS=(COLOR="Gray") PERCENTILE=4 ;
SCATTER X = An_Run Y = Anal_Biol / JITTER MARKERCHAR=Outlier MARKERCHARATTRS=(COLOR="Red") ;
RUN ;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
/*
You could combine them together 
*/
data have;
input x y outlier $1.;
cards;
2 5 A
3 8 B
3 8 B
3 8 A
3 4 A
3 8 A
3 9 B
4 3 B
4 3 B
4 3 B
4 4 A
6 8 B
5 9 A
2 8 A
;

proc sort data=have out=temp;by x y;run;
data want; 
do until(last.y);
 set temp;
 by x y;
 length label $ 80;
 label=cats(label,outlier);
end;
run;
proc sgplot data=want noautolegend;
scatter x=x y=y /markerchar=label markercharattrs=(color=red size=10) labelstrip ;
run;

Ksharp_0-1673523336606.png

 

View solution in original post

7 REPLIES 7
sbxkoenk
SAS Super FREQ

Hello @aabdesse ,

 

If jittering is requested with Marker Characters at a high DPI, then the marker characters seem to collide.

 

It's not considered as a bug.

 

I think it's in the documentation somewhere ...
... that jittering is not supported when MARKERCHARACTER= or MARKERSIZERESPONSE= is in effect.

 

SAS does not always issue a LOG message when interaction of options like this happens.

 

So, the behaviour you see is documented.
However , how to achieve what you want to achieve? About the latter, I still need to think a bit. 😉

More news later (hopefully).

 

Cheers,
Koen

 
Ksharp
Super User
/*
If you want answer, 
you should post some data to test your code.
*/
data have;
input x y outlier $;
cards;
2 5 A
3 8 B
3 8 B
3 8 A
3 8 A
4 3 B
4 3 B
4 3 B
6 8 B
5 9 A
2 8 A
;

proc sort data=have out=temp;by x y;run;
data temp;
 set temp;
 by x y;
 if first.y then group=0;
 group+1;
run;
proc sgplot data=temp noautolegend;
scatter x=x y=y /markerchar=outlier markercharattrs=(color=red size=10)
   group=group groupdisplay=cluster clusterwidth=0.3;
run;

Ksharp_0-1673350932236.png

 

aabdesse
Fluorite | Level 6

This looks good! There is only one issue I encounter when doing it this way. If I add more y values for the same x values (on the same vertical line), then the values that are not grouped together are not centered with the vertical line corresponding to the x value. I've added a few values to your example to illustrate it. Is there any way to keep everything centered? With my actual dataset, I also have boxplots in the same plot, and it looks odd when the points are not centered. Thanks!

 

data have;
input x y outlier $;
cards;
2 5 A
3 8 B
3 8 B
3 8 A
3 4 A
3 8 A
4 3 B
4 3 B
4 3 B
4 4 A
6 8 B
5 9 A
2 8 A
;

proc sort data=have out=temp;by x y;run;
data temp;
 set temp;
 by x y;
 if first.y then group=0;
 group+1;
run;
proc sgplot data=temp noautolegend;
scatter x=x y=y /markerchar=outlier markercharattrs=(color=red size=10)
   group=group groupdisplay=cluster clusterwidth=0.3;
run;

SGPlot.png

Ksharp
Super User
/*
This code is more simple.
DATALABEL has the same effect with JITTER.
*/

data have;
input x y outlier $;
cards;
2 5 A
3 8 B
3 8 B
3 8 A
3 8 A
4 3 B
4 3 B
4 3 B
6 8 B
5 9 A
2 8 A
;


proc sgplot data=have noautolegend;
scatter x=x y=y /datalabel=outlier markerattrs=(size=0) datalabelattrs=(size=10 color=red) ;
run;

Ksharp_0-1673437392485.png

 

aabdesse
Fluorite | Level 6

The code above is indeed simpler, however it offsets the position on the y axis when there are more than 2 values, whereas your previous example keeps them all on the same level (which for me is important as I am dealing with continuous values on the y-axis as opposed to discrete ones like in your example). 

Ksharp
Super User
/*
You could combine them together 
*/
data have;
input x y outlier $1.;
cards;
2 5 A
3 8 B
3 8 B
3 8 A
3 4 A
3 8 A
3 9 B
4 3 B
4 3 B
4 3 B
4 4 A
6 8 B
5 9 A
2 8 A
;

proc sort data=have out=temp;by x y;run;
data want; 
do until(last.y);
 set temp;
 by x y;
 length label $ 80;
 label=cats(label,outlier);
end;
run;
proc sgplot data=want noautolegend;
scatter x=x y=y /markerchar=label markercharattrs=(color=red size=10) labelstrip ;
run;

Ksharp_0-1673523336606.png

 

aabdesse
Fluorite | Level 6

That's perfect! Thank you so much!

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
  • 7 replies
  • 1761 views
  • 6 likes
  • 3 in conversation