BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SASuserlot
Barite | Level 11

Please tell me if it's a stupid question.  I am looking to create a bubble graph. But I want to change the shape of the bubble. Is that possible? (this may be a stupid question sorry!); if it's not possible, is there any other alternative way. Thanks

Code  Credits  :Sanjay Matange

reference:  https://blogs.sas.com/content/graphicallyspeaking/files/2015/06/Bubble.txt

%let gpath='.';
%let dpi=200;

ods html close;
ods listing gpath=&gpath image_dpi=&dpi;

/*--Create Bubble Data--*/
/*--Areas of min and max bubble size is computed--*/
data bubble;
  format Area  4.1 size 2.0;
  format LinArea PropArea 4.0;
  pi=constant("pi");
  input X Y Size Type $ Cat $;
  /*--Area of bubble with Size as redius--*/
  Area=size*size*pi/4;

  /*--Min and max size of bubbles on screen and areas--*/
  maxR=3*7; minR=7;
  MaxArea=maxR*maxR*pi; 
  MinArea=minR*minR*pi;
  Max=15; Min=13;

  /*--Area of bubble using linear scaling--*/
  LinArea= MinArea+(Size-Min)*(maxArea-minArea)/(Max-Min); 

  /*--Area of bubble using Proportional scaling--*/
  PropArea= Size*maxArea/max;

  LinLbl='ValueArea=' || put (area, 4.0) || '-PixelArea=' || put(LinArea, 4.1);
  PropLbl='ValueArea=' || put (area, 4.0) || '-PixelArea=' || put(PropArea, 4.1);
 
  datalines;
 20   20   14  A  X
 50   10   13  B  Y
 80   60   15  A  Z
;
run;
ods html;
proc print;run;
ods html close;
ods path(prepend) work.templat(update);
/*--Bubble Chart with Linear scaling--*/
ods graphics / reset attrpriority=color width=4in height=2.8in imagename='Bubble_Linear_SG';
/*--Bubble Chart with Proportional scaling--*/
proc template;
  define statgraph Bubble;
    begingraph;
      entrytitle 'Proportional Bubble Size - GTL'; ;
      layout overlay /   aspectratio=0.7 xaxisopts=(display=(ticks tickvalues line) griddisplay=on 
                                    linearopts=(viewmin=0 viewmax=100) offsetmin=0 offsetmax=0.1)
                             yaxisopts=(display=(ticks tickvalues line) griddisplay=on
                                    linearopts=(viewmin=0 viewmax=70) offsetmin=0 offsetmax=0.1);
            bubbleplot x=x y=y size=size/ group=type datalabel=PropLbl relativescaletype=proportional 
                   datalabelsplit=true datalabelsplitchar='-' name='a' dataskin=sheen
                   display=(fill);
            textplot x=x y=y text=size / position=center;

      endlayout;
        endgraph;
  end;
run;

/*--Bubble Chart with Proportional scaling--*/
ods graphics / reset width=4in height=2.8in imagename='Bubble_Prop_GTL';
proc sgrender data=bubble template=bubble;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

Instead of using a BUBBLEPLOT, use a SCATTERPLOT with the SIZERESPONSE option to have the marker size vary by data value. the SIZEMIN and SIZEMAX options can be used to change the min and max size range of the markers. Then, just use MARKERATTRS=(symbol=<some symbol>) to set the shape you want.

 

Hope this helps!

Dan

View solution in original post

2 REPLIES 2
DanH_sas
SAS Super FREQ

Instead of using a BUBBLEPLOT, use a SCATTERPLOT with the SIZERESPONSE option to have the marker size vary by data value. the SIZEMIN and SIZEMAX options can be used to change the min and max size range of the markers. Then, just use MARKERATTRS=(symbol=<some symbol>) to set the shape you want.

 

Hope this helps!

Dan

SASuserlot
Barite | Level 11

Thank you it worked.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 540 views
  • 5 likes
  • 2 in conversation