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.
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.
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.
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
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.
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;
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
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.