Data visualization with SAS programming

Proc sgplot: plotting different colors and markers for several groups in a scatter plot

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 18
Accepted Solution

Proc sgplot: plotting different colors and markers for several groups in a scatter plot

Hi All, I'm running SAS 9.4 and trying to plot a scatter plot with 5 groups, using proc sgplot. I would like my groups on the scatter plot to have different markers than the standard open circle and different colors. I did some hunting online and thought I found a possible solution, however it has not worked.

 

 

%modstyle ( parent=analysis,
name=mystyle,
type=CLM,
colors=green blue yellow orange red,
markers=circle plus diamond asterisk circlefilled);

 

ods listing style=mystyle;

proc sgplot data=hospitals;
scatter x=avg_payment y=score/group=rank;
run;

 

Does anyone have any insight in how to change the scatter plot markers & colors? Thanks! 


Accepted Solutions
Solution
‎08-18-2016 01:43 PM
Grand Advisor
Posts: 16,411

Re: Proc sgplot: plotting different colors and markers for several groups in a scatter plot


All Replies
Solution
‎08-18-2016 01:43 PM
Grand Advisor
Posts: 16,411

Re: Proc sgplot: plotting different colors and markers for several groups in a scatter plot

Attribute Maps

 

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

A full example is here

 

http://blogs.sas.com/content/graphicallyspeaking/2012/02/27/roses-are-red-violets-are-blue/

 

Theres probably newer ever stuff on here if you search with the term attribute map. 

Occasional Contributor
Posts: 18

Re: Proc sgplot: plotting different colors and markers for several groups in a scatter plot

Thanks for your response. i tried your suggestion, sadly it didn't work for me. Here is my code:

 

data myattrmap;
length linecolor $ 9 fillcolor $ 9;
input ID $ value $ linecolor $ fillcolor $;
datalines;
myid 1 blue blue
myid 2 yellow yellow
myid 3 green green
myid 4 orange orange
myid 5 red red
;

run;

 

 

proc sgplot data=hospitals dattrmap=myattrmap;
scatter x=avg_payment y=score/group=rank attrid=myid;;
run;

 

Is there something that I'm missing. Also, is there a way to also change the marker using this method? Might this be an issue since I'm using enterprise? 

 

Thanks! 

SAS Super FREQ
Posts: 864

Re: Proc sgplot: plotting different colors and markers for several groups in a scatter plot

Add markercolor to your dataset to change the marker colors.

Occasional Contributor
Posts: 18

Re: Proc sgplot: plotting different colors and markers for several groups in a scatter plot

Thanks that worked for the colors, what would I need to add to change the marker style from an open circle, say to a asterisk? 

Occasional Contributor
Posts: 18

Re: Proc sgplot: plotting different colors and markers for several groups in a scatter plot

Actually answered my own question. Need to add markersymbol. 

 

http://support.sas.com/documentation/cdl/en/grstatgraph/67882/HTML/default/viewer.htm#n1oq0axfb1tc1y...

 

 

SAS Super FREQ
Posts: 1,044

Re: Proc sgplot: plotting different colors and markers for several groups in a scatter plot

Reeza's solution will work, especially if you want specific colors and symbols for specific group values.  If you want custom colors and symbols, but don't care which group value gets which one, you can use the STYLEATTRS statement in SGPLOT.  Use the DataColors, DataContrastColors, DataSymbols and DataLinePatterns to provide your own list of attributes each.  Also, be sure to use ATTRPRIORITY=None to ensure you get color and symbol cycling.

Post a Question
Discussion Stats
  • 6 replies
  • 522 views
  • 4 likes
  • 4 in conversation