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 open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.