HI, dose anyone has insight to create the following figure?
OK, one more try, following @Jay54's suggestion (tested with 9.4) :
proc sql;
create table class as
select *, median(weight) as med
from sashelp.class
group by age;
quit;
proc sgplot data=class noautolegend;
highlow x=age high=med low=med / type=bar lineattrs=(thickness=2 color=red) barwidth=0.6;
scatter y=weight x=age / markerattrs=(symbol=circlefilled color=blue);
xaxis type=discrete;
run;
We could try the sgplot procedure as below, I am assuming that the graph is overlapping of scatter plot on box plot with mean. If it is the case the below procedure should help.
proc sgplot data=have;
scatter x=feed_type y=weight / markerattrs = (size = 2 symbol = circlefilled); /*this will be the scatter plot*/
vbox weight / category=feed_type; /*this will create the box plot with mean*/
quit;
run;
Hi Jagadishkatam,
It seems that the overlapping scatter plot and box plot is not worked.
Please see the SAS log below.
Thanks for your reply.
By the way, I'm using SAS 9.3.
I guess in 9.3 you could cheat this way:
proc sql;
create table class as
select *, median(weight) as med
from sashelp.class
group by age;
quit;
proc sgplot data=class noautolegend;
scatter x=age y=med / yerrorlower=med yerrorupper=med
markerattrs=(size=0) errorbarattrs=(thickness=2 color=red);
scatter y=weight x=age / markerattrs=(symbol=circlefilled color=blue);
run;
I don't know. Seems to be proportional to line thickness.
Looks like variation on a box plot.
http://blogs.sas.com/content/graphicallyspeaking/2012/05/07/unbox-your-box-plots/
Here is an approaching example:
proc sql;
create table class as
select *, median(weight) as med
from sashelp.class
group by age;
quit;
proc sgplot data=class noautolegend;
vbox med / category=age nomean nomedian nocaps
lineattrs=(color=red thickness=2);
scatter y=weight x=age / markerattrs=(symbol=circlefilled);
xaxis type=discrete;
run;
If you know the value for drawing the mean or median (the red line), and are using SAS 9.3, I suggest overlaying a Scatter and a HighLow (Type=Bar). Make the high and low the same value to get a single line. You can set the BarWidth to control the width of the line.
OK, one more try, following @Jay54's suggestion (tested with 9.4) :
proc sql;
create table class as
select *, median(weight) as med
from sashelp.class
group by age;
quit;
proc sgplot data=class noautolegend;
highlow x=age high=med low=med / type=bar lineattrs=(thickness=2 color=red) barwidth=0.6;
scatter y=weight x=age / markerattrs=(symbol=circlefilled color=blue);
xaxis type=discrete;
run;
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!
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.