BookmarkSubscribeRSS Feed
rebeccabarton
Fluorite | Level 6

Hi, 

 

I'm trying to create a scatter plot with two continuous variables. I'd then like to colour the plots according to a third, categorical variable.

 

Is this possible? 

 

My code so far is

 

proc sgplot data = sasuser.data1;
scatter x = tradingyears y = sales2015;
run;

5 REPLIES 5
Reeza
Super User

Of course! 

Try adding the third variable as a GROUP var in your scatter statement. Example 1 in the documentation covers this 

http://support.sas.com/documentation/cdl/en/grstatproc/69716/HTML/default/viewer.htm#n06fb9ichgg6akn...

 

If you want to control the colours see the post below

http://blogs.sas.com/content/iml/2012/10/17/specify-the-colors-of-groups-in-sas-statistical-graphics...

 

Possibly more than you need now, but good to know:

http://blogs.sas.com/content/iml/2017/01/30/auto-discrete-attr-map.html

 

rebeccabarton
Fluorite | Level 6

Thanks, this is perfect, is it also possible to set the colour of the whole plot simply? 

Reeza
Super User

I'm not sure what you mean by 'whole plot'? 

 

Colours are usually defined by the Style set. If you're using SAS Studio this is likely HTMLBlue. For publications the style Journal/Journal1 are good. For a clean compact look, I like the Seaside and Meadow styles. Finally, there's a post on here that has the style definition in the style of Stephen Few. 

rebeccabarton
Fluorite | Level 6

Sorry I meant if I wanted to change the colour of the plots, when not splitting by the categorical variable. So just each dot.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 5 replies
  • 879 views
  • 0 likes
  • 3 in conversation