Data visualization with SAS programming

Now to create scatter plot like this?

Accepted Solution Solved
Reply
Contributor
Posts: 56
Accepted Solution

Now to create scatter plot like this?

HI, dose anyone has insight to create the following figure?

 

dotwithmedian_baser.png 


Accepted Solutions
Solution
‎03-15-2017 10:44 PM
Respected Advisor
Posts: 4,608

Re: Now to create scatter plot like this?

OK, one more try, following @Sanjay_SAS'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;

SGPlot6.png 

PG

View solution in original post


All Replies
Super User
Posts: 1,116

Re: Now to create scatter plot like this?

[ Edited ]

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;

 

Thanks,
Jag
Contributor
Posts: 56

Re: Now to create scatter plot like this?

[ Edited ]

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.

 

未命名.png

 

By the way, I'm using SAS 9.3.

Respected Advisor
Posts: 4,608

Re: Now to create scatter plot like this?

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;

SGPlot8.png

PG
Contributor
Posts: 56

Re: Now to create scatter plot like this?

Hi PG Stats,

Thanks for your solution.
Another question, how to lengthen the length of 'mean'?
Respected Advisor
Posts: 4,608

Re: Now to create scatter plot like this?

I don't know. Seems to be proportional to line thickness.

PG
Contributor
Posts: 56

Re: Now to create scatter plot like this?

Okay. I will try.
According to your reply, SAS 9.3 cannot overlay vbox and scatter plot, right?
Grand Advisor
Posts: 17,378

Re: Now to create scatter plot like this?

Respected Advisor
Posts: 4,608

Re: Now to create scatter plot like this?

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;

SGPlot5.png

PG
SAS Super FREQ
Posts: 1,081

Re: Now to create scatter plot like this?

[ Edited ]

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.

Solution
‎03-15-2017 10:44 PM
Respected Advisor
Posts: 4,608

Re: Now to create scatter plot like this?

OK, one more try, following @Sanjay_SAS'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;

SGPlot6.png 

PG
Contributor
Posts: 56

Re: Now to create scatter plot like this?

I'm creating the figure by your suggestion. Great thanks for everyone's suggestion!
Besides, the function "median" seems not okay in SAS 9.3. There will be a warning message "The MEDIAN function has been called with only one argument.".
However, 'mean' function can be worked in proc sql statement and that what I need!

Thanks again!

JC
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 11 replies
  • 3342 views
  • 5 likes
  • 5 in conversation