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

I want to create a plot as written below (scatter plot with graduated color response by a third variable), except add a fourth group variable identified by the shape of the marker.
For example, there will be two groups, circles and triangles, each having graduated color scheme all on the same x-y plot.

proc sgplot data=mydata;
scatter x=variable1 y=variable2 / colorresponse=variable3
markerattrs=(symbol=CircleFilled)
colormodel=(CX3288BD CX99D594 CXE6F598 CXFEE08B CXFC8D59 CXD53E4F);
run;

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

Here is a little more complete example, forcing only filled markers, and adding a KEYLEGEND to show your shape values.

 

proc sgplot data=sashelp.class;
  styleattrs datasymbols=(circlefilled squarefilled trianglefilled diamondfilled);
  series x=weight y=height / colorresponse=age  group=sex groupms=sex
         markers lineattrs=(thickness=0) name="scat"
         colormodel=(CX3288BD CX99D594 CXE6F598 CXFEE08B CXFC8D59 CXD53E4F);
  gradlegend "scat";
  keylegend "scat" / type=markersymbol;
run;

View solution in original post

6 REPLIES 6
DanH_sas
SAS Super FREQ

Yes, this can be done; but it requires a little slight-of hand 🙂

 

As you have probably found, you cannot use both a GROUP and a COLORRESPONSE in the SCATTER plot (the GROUP is ignored). However, SERIES plots have additional options that give you the ability to control visual attributes with additional class variables. So, to get what you want, do the following:

 

1. Change SCATTER to SERIES

2. Add the MARKERS option to turn on the markers.

3. Set LINEATTRS=(thickness=0) /* You don't want to see the lines */

4. Set GROUP=<your class variable> to get grouping

5. Set GROUPMS=<the same class variable> to vary only the marker symbol (COLORRESPONSE will control the color)

 

Here is a simple example adapting your original code:

 

proc sgplot data=sashelp.class;
series x=weight y=height / colorresponse=age  group=sex groupms=sex
markers lineattrs=(thickness=0)
colormodel=(CX3288BD CX99D594 CXE6F598 CXFEE08B CXFC8D59 CXD53E4F);
run;

Hope this helps!

Dan

DanH_sas
SAS Super FREQ

Here is a little more complete example, forcing only filled markers, and adding a KEYLEGEND to show your shape values.

 

proc sgplot data=sashelp.class;
  styleattrs datasymbols=(circlefilled squarefilled trianglefilled diamondfilled);
  series x=weight y=height / colorresponse=age  group=sex groupms=sex
         markers lineattrs=(thickness=0) name="scat"
         colormodel=(CX3288BD CX99D594 CXE6F598 CXFEE08B CXFC8D59 CXD53E4F);
  gradlegend "scat";
  keylegend "scat" / type=markersymbol;
run;
Vic3
Fluorite | Level 6
Thank you very much! This worked perfectly.
Vic3
Fluorite | Level 6

I labeled your more complicated version as a solution, but the first, simpler code actually provides better visualization in some situations. I'll be using it too. Thank you again!

Ksharp
Super User

OR this one ?

 

ods graphics/ attrpriority=none;
proc sgplot data=sashelp.class;
  styleattrs datasymbols=(circlefilled squarefilled trianglefilled diamondfilled);
  scatter x=weight y=height / colorresponse=age  group=sex
        name="scat"
         colormodel=(CX3288BD CX99D594 CXE6F598 CXFEE08B CXFC8D59 CXD53E4F);
  gradlegend "scat";
  keylegend "scat" ;
run;
DanH_sas
SAS Super FREQ

@Ksharp is correct -- I was overthinking this one. The ATTRPRIORITY option is the key here. If possible, we should adjust the recommended solution to his post.

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!
How to Concatenate Values

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.

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
  • 965 views
  • 3 likes
  • 3 in conversation