In proc gplot,
Is there a way to overlay scatter plots for multiple groups using different symbols when the data is arranged below? Currently, the only way I know how to do this is to create a separate column of Ys for the A and B group... but if I have more than 2 groups this becomes tedious.
Thanks
group | X | Y |
A | 1 | 2.0 |
A | 1 | 2.2 |
A | 2 | 3.1 |
A | 2 | 3.3 |
A | 3 | 4.2 |
A | 3 | 4.6 |
A | 4 | 3.9 |
A | 4 | 4.3 |
A | 5 | 6.1 |
A | 5 | 5.9 |
A | 6 | 7.5 |
A | 6 | 7.3 |
B | 1.1 | 0.5 |
B | 1.1 | 0.5 |
B | 2.1 | 1.4 |
B | 2.1 | 1.5 |
B | 3.1 | 2.9 |
B | 3.1 | 3.2 |
B | 4.1 | 3.6 |
B | 4.1 | 3.9 |
B | 5.1 | 6.9 |
B | 5.1 | 6.7 |
B | 6.1 | 10.2 |
B | 6.1 | 9.9 |
I suggest you use PROC SGPLOT instead and do something like this
data have;
input group $ X Y;
datalines;
A 1 2.0
A 1 2.2
A 2 3.1
A 2 3.3
A 3 4.2
A 3 4.6
A 4 3.9
A 4 4.3
A 5 6.1
A 5 5.9
A 6 7.5
A 6 7.3
B 1.1 0.5
B 1.1 0.5
B 2.1 1.4
B 2.1 1.5
B 3.1 2.9
B 3.1 3.2
B 4.1 3.6
B 4.1 3.9
B 5.1 6.9
B 5.1 6.7
B 6.1 10.2
B 6.1 9.9
;
ods graphics / AttrPriority=None;
proc sgplot data=have;
styleattrs datasymbols=(circlefilled squarefilled starfilled)
datacontrastcolors=(red green red);
scatter x=x y=y / group=group;
run;
Result:
I suggest you use PROC SGPLOT instead and do something like this
data have;
input group $ X Y;
datalines;
A 1 2.0
A 1 2.2
A 2 3.1
A 2 3.3
A 3 4.2
A 3 4.6
A 4 3.9
A 4 4.3
A 5 6.1
A 5 5.9
A 6 7.5
A 6 7.3
B 1.1 0.5
B 1.1 0.5
B 2.1 1.4
B 2.1 1.5
B 3.1 2.9
B 3.1 3.2
B 4.1 3.6
B 4.1 3.9
B 5.1 6.9
B 5.1 6.7
B 6.1 10.2
B 6.1 9.9
;
ods graphics / AttrPriority=None;
proc sgplot data=have;
styleattrs datasymbols=(circlefilled squarefilled starfilled)
datacontrastcolors=(red green red);
scatter x=x y=y / group=group;
run;
Result:
That's even better. Great.
I also figured out the answer to my question.
proc gplot;
plot Y*X=group;
run;
glad you found your answer. In my book, PROC SGPLOT is more intuitive 🙂
Please remember to close the thread.
@iiibbb wrote:
That's even better. Great.
I also figured out the answer to my question.
proc gplot;plot Y*X=group;
run;
You would provide a different symbol statement for each "group" value to control marker type, size, color, line color, type and width if you don't like the defaults.
Follow up question. How do you set the axis ranges in sgplot?
Like this
ods graphics / AttrPriority=None;
proc sgplot data=have;
styleattrs datasymbols=(circlefilled squarefilled starfilled)
datacontrastcolors=(red green red);
scatter x=x y=y / group=group;
xaxis min=0 max=10;
yaxis min=0 max=10;
run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.