BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
iiibbb
Quartz | Level 8

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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:

 

 

Capture.PNG

View solution in original post

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

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:

 

 

Capture.PNG

iiibbb
Quartz | Level 8

That's even better.  Great.


I also figured out the answer to my question.

proc gplot;

plot Y*X=group;
run;

PeterClemmensen
Tourmaline | Level 20

glad you found your answer. In my book, PROC SGPLOT is more intuitive 🙂

 

Please remember to close the thread.

ballardw
Super User

@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.

iiibbb
Quartz | Level 8

Follow up question.  How do you set the axis ranges in sgplot?

PeterClemmensen
Tourmaline | Level 20

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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 2083 views
  • 4 likes
  • 3 in conversation