Data visualization with SAS programming

proc sgplot bubble plot with group coloring

Accepted Solution Solved
Reply
Regular Contributor
Posts: 201
Accepted Solution

proc sgplot bubble plot with group coloring

I am using this macrotised code:

 

%macro PlotMacro(Title, Footnote, X, Y, Z);
	title &Title.;
	proc sgplot data=SomeData 
		noautolegend;
	  bubble X = &X. Y = &Y. size= &Z. /  
	    transparency=0.4 datalabelattrs=(size=9 weight=bold);
	run;
%mend;

Is there a way to color the bubbles according to a 'group/class' column in SomeData.


Accepted Solutions
Solution
‎01-24-2018 11:16 AM
PROC Star
Posts: 1,193

Re: proc sgplot bubble plot with group coloring

[ Edited ]
Posted in reply to csetzkorn

Use the GROUP= option in the bubble statement after the / as in this very simple example

 

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

 

Also, why do you use a macro to do this? It just seems like more typing to me.

View solution in original post


All Replies
Solution
‎01-24-2018 11:16 AM
PROC Star
Posts: 1,193

Re: proc sgplot bubble plot with group coloring

[ Edited ]
Posted in reply to csetzkorn

Use the GROUP= option in the bubble statement after the / as in this very simple example

 

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

 

Also, why do you use a macro to do this? It just seems like more typing to me.

Super Contributor
Posts: 261

Re: proc sgplot bubble plot with group coloring

Posted in reply to csetzkorn

Hi,

 

There is a group option in the Bubble statement. I believe you can use that to color the bubbles, i.e. group=column (in Somedata)

 

Many thanks,

 

Kriss

SAS Employee
Posts: 13

Re: proc sgplot bubble plot with group coloring

Posted in reply to csetzkorn

The bubble plot supports the group option which will color the bubbles based on a character variable.  It also supports the color response option which will color the bubbles based on a numeric variable. 

Regular Contributor
Posts: 201

Re: proc sgplot bubble plot with group coloring

Posted in reply to ScottS_SAS
Thanks. I just noticed this. I use ... /group = Bla. Any idea how I can add a legend based on Bla?
PROC Star
Posts: 1,193

Re: proc sgplot bubble plot with group coloring

Posted in reply to csetzkorn

Something like in this example?

 

title "Bubble plot by Sex";
proc sgplot data=sashelp.class noautolegend;
  bubble x=height y=weight size=age / group=sex;
  keylegend / position=nw location=inside across=1;
run;
SAS Employee
Posts: 13

Re: proc sgplot bubble plot with group coloring

The sgplot procedure will automatically create a legend based on the group variable.  Remove the no auto legend from your program, and you should then see the legend. 

Thanks

Scott

Regular Contributor
Posts: 201

Re: proc sgplot bubble plot with group coloring

Posted in reply to ScottS_SAS
Just noticed that I had noautolegend - removing that shows the legend.
☑ This topic is solved.

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

Discussion stats
  • 7 replies
  • 157 views
  • 3 likes
  • 4 in conversation