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;
Of course!
Try adding the third variable as a GROUP var in your scatter statement. Example 1 in the documentation covers this
If you want to control the colours see the post below
Possibly more than you need now, but good to know:
http://blogs.sas.com/content/iml/2017/01/30/auto-discrete-attr-map.html
Thanks, this is perfect, is it also possible to set the colour of the whole plot simply?
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.
Sorry I meant if I wanted to change the colour of the plots, when not splitting by the categorical variable. So just each dot.
See "Three ways to specify colors in SAS statistical procedures." Also see the documentation for the SCATTER statement, especially the MARKERATTRS= option.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.