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

I'm using the following code to  create box plots and I would like to overlay the boxplot output with a specific point in the distribution(e.g. most recent value ) in order to show where we stand currently versus the historical distribution.  Is there a way to easily highlight a specific value in the box plot. 

 


proc sort data = Regionbets ; by region; run;
ods path reset;
ODS path show;
ods path(prepend) work.templat(update);

proc template;
define statgraph boxplot;
begingraph;
entrytitle "Country bets ";
layout overlay;
boxplot y=actweight x=region/
datalabel=make spread=true;
endlayout;
endgraph;
end;
run;

proc sgrender data=Regionbets template=boxplot;
label Region="test regions"
label actweight="Active";
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

Yes, something like that. From your initial description, my expectation is that you will have one scatter point per box. Using your code:

 

proc sort data = Regionbets ; by region; run;
ods path reset;
ODS path show;
ods path(prepend) work.templat(update);
proc template;
define statgraph boxplot;
begingraph;
   entrytitle "Country bets ";
   layout overlay;
      boxplot y=actweight x=region / datalabel=make spread=true;
      scatterplot y=curpoint x=region2 / markerattrs=(symbol=starfilled);
   endlayout;
endgraph;
end;
run;
proc sgrender data=Regionbets template=boxplot;
label Region="test regions"
label actweight="Active";
run;

 

Where "curpoint" contains the current points for each box, and "region2" is the corresponding region value for the point. THese two columns should be merged with your original data into a "merged" data set using a DATA step.

 

Hope this helps!

Dan

View solution in original post

5 REPLIES 5
DanH_sas
SAS Super FREQ

Probably the most straighfroward way it to overlay a scatterplot on the boxplot and set the marker symol different from the outlier markers.

mgm
Fluorite | Level 6 mgm
Fluorite | Level 6

Something along the following lines  ? http://support.sas.com/resources/papers/proceedings12/285-2012.pdf

 

proc sort data=sashelp.cars; by DRIVETRAIN; run; data cars2; set sashelp.cars; if DRIVETRAIN="All" then ALL=-1+0.1*rannor(0); if DRIVETRAIN="Front" then FRONT=1.5+0.1*rannor(0); if DRIVETRAIN="Rear" then REAR=4+0.1*rannor(0); run; proc template; define statgraph mygraphs.example5; begingraph; layout overlay / x2axisopts=(display=(line) linearopts=(viewmin=-1 viewmax=4)); boxplot x=DRIVETRAIN y=MPG_CITY / display=(caps mean median) fillattrs=(color=white); scatterplot x=ALL y=MPG_CITY / xaxis=x2 markerattrs=(color=blue); scatterplot x=FRONT y=MPG_CITY / xaxis=x2 markerattrs=(color=red); scatterplot x=REAR y=MPG_CITY / xaxis=x2 markerattrs=(color=green); endlayout; endgraph; end; run; Figure 6b
ballardw
Super User

@mgm wrote:

Something along the following lines  ? http://support.sas.com/resources/papers/proceedings12/285-2012.pdf

 


 

 

@mgm It is a good idea to post code in the Code box opened using the SAS "Run" icon to reduce poorly formatted posts.

DanH_sas
SAS Super FREQ

Yes, something like that. From your initial description, my expectation is that you will have one scatter point per box. Using your code:

 

proc sort data = Regionbets ; by region; run;
ods path reset;
ODS path show;
ods path(prepend) work.templat(update);
proc template;
define statgraph boxplot;
begingraph;
   entrytitle "Country bets ";
   layout overlay;
      boxplot y=actweight x=region / datalabel=make spread=true;
      scatterplot y=curpoint x=region2 / markerattrs=(symbol=starfilled);
   endlayout;
endgraph;
end;
run;
proc sgrender data=Regionbets template=boxplot;
label Region="test regions"
label actweight="Active";
run;

 

Where "curpoint" contains the current points for each box, and "region2" is the corresponding region value for the point. THese two columns should be merged with your original data into a "merged" data set using a DATA step.

 

Hope this helps!

Dan

Rick_SAS
SAS Super FREQ

There have been several discussions recently about overlaying scatter plots or series plots on box plots.  I've summarized some of my thoughts and presented some examples on my blog:

1. Overlay plots on a box plot in SAS: Discrete X axis

2. Overlay plots on a box plot in SAS: Continuous X axis

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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