## proc sgplot bubble plot with group coloring

Solved
Regular Contributor
Posts: 201

# 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 ]

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.

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

## Re: proc sgplot bubble plot with group coloring

[ Edited ]

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

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

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

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

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