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;
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
Probably the most straighfroward way it to overlay a scatterplot on the boxplot and set the marker symol different from the outlier markers.
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
@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.
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
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 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.