BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
csetzkorn
Lapis Lazuli | Level 10

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.

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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

7 REPLIES 7
PeterClemmensen
Tourmaline | Level 20

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.

djrisks
Barite | Level 11

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

ScottS_SAS
SAS Employee

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. 

csetzkorn
Lapis Lazuli | Level 10
Thanks. I just noticed this. I use ... /group = Bla. Any idea how I can add a legend based on Bla?
PeterClemmensen
Tourmaline | Level 20

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;
ScottS_SAS
SAS Employee

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

csetzkorn
Lapis Lazuli | Level 10
Just noticed that I had noautolegend - removing that shows the legend.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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