Data visualization with SAS programming

proc sgplot bubble plot with group coloring - specify group color

Accepted Solution Solved
Reply
Regular Contributor
Posts: 201
Accepted Solution

proc sgplot bubble plot with group coloring - specify group color

Using this code:

 

title "Bubble plot by Sex";
proc sgplot data=sashelp.class;
  bubble x=height y=weight size=age / group=sex;
run;

 Is there a way to assign a specific color to each level in the sex column (e.g. male=green, female=red)


Accepted Solutions
Solution
‎01-25-2018 09:41 AM
SAS Super FREQ
Posts: 4,110

Re: proc sgplot bubble plot with group coloring - specify group color

[ Edited ]
Posted in reply to csetzkorn

If you know the order of the categories and you only want to do this one time, you can use the STYLEATTRS statement:

 

proc sgplot data=sashelp.class;
  styleattrs datacolors=(blue pink);
  bubble x=height y=weight size=age / group=sex;
run;

For more complicated scenarios, discrete data maps are more powerful and flexible, as Warren said.

View solution in original post


All Replies
SAS Super FREQ
Posts: 496

Re: proc sgplot bubble plot with group coloring - specify group color

Posted in reply to csetzkorn
Solution
‎01-25-2018 09:41 AM
SAS Super FREQ
Posts: 4,110

Re: proc sgplot bubble plot with group coloring - specify group color

[ Edited ]
Posted in reply to csetzkorn

If you know the order of the categories and you only want to do this one time, you can use the STYLEATTRS statement:

 

proc sgplot data=sashelp.class;
  styleattrs datacolors=(blue pink);
  bubble x=height y=weight size=age / group=sex;
run;

For more complicated scenarios, discrete data maps are more powerful and flexible, as Warren said.

Regular Contributor
Posts: 201

Re: proc sgplot bubble plot with group coloring - specify group color

thanks - Warren's suggestion is great but probably overkill for my situation. I am getting ERROR 180-322: Statement is not valid or it is used out of proper order. when I add the line styleattrs ... any ideas?
PROC Star
Posts: 1,190

Re: proc sgplot bubble plot with group coloring - specify group color

Posted in reply to csetzkorn

Please post your log where the error appear?

SAS Super FREQ
Posts: 4,110

Re: proc sgplot bubble plot with group coloring - specify group color

Posted in reply to csetzkorn

The STYLEATTRS statement was added in SAS 9.4. , so if you are running an old version of SAS you would get an error like you are seeing.

Regular Contributor
Posts: 201

Re: proc sgplot bubble plot with group coloring - specify group color

OK thanks makes sense. I will run this in the newer env.
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 205 views
  • 3 likes
  • 4 in conversation