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

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
Obsidian | Level 7
Thank you very much! This worked perfectly.
Vic3
Obsidian | Level 7

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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1336 views
  • 3 likes
  • 3 in conversation