Hi everyone,
Running a simple program to produce a bubble plot as shown below. But when I run it, the output plot shows the max events on the X axis as 20, but it puts the max value in the middle of the graph space and nothing but empty space to the right. If I add offsetmax=0 to the xaxis definition line, then it works as I would expect. I am not sure I understand why the default value of offsetmax stops at the mid point. Looking at the documentation, the default value "should" have auto filled the xaxis across the full width of the graph. Any thoughts?
ods graphics on / reset=all;
ods graphics / width = 100pct height = 100pct;
title 'Total Cost by Events and $ per Event';
proc sgplot data=work.myData noautolegend;
bubble x=events y=cost size=Total_Cost/ group=subsystem datalabel=subsystem
transparency=0.4 datalabelattrs=(size=9 weight=bold);
yaxis grid ;
xaxis grid values=(0 to 20 by 5) integer ;
run;
ods graphics off;
My guess is that the length of the 'subsystem' variable is large (like 80). When you use a character variable as the argument to the DATALABEL= option, the plot will leave room for the maximum length. You can either change the length of the variable when it is created or I think you can add
format subsystem $10.;
after the PROC SGPLOT statement.
Since setting OFFSETMAX helps, that may be a clue. Displaying data label causes the offsets to be set on all sides so the text will not be clipped. Remove the data label and see if you get the right result. If yes, then you do need to set the offsetmin or max to remove the excess offsets. Or, you can use a TEXT plot to display the labels. Text plot allows better control on offsets.
From your program, it appears that the "event" variable to probably character, making the X axis discrete. When using bubbles with a discrete axis, the axis offsets will automatically adjust to accommodate the possibility of the largest bubble being on the end. As you found, you can override this behavior using OFFSETMIN/OFFSETMAX.
Hope this helps!
Dan
My guess is that the length of the 'subsystem' variable is large (like 80). When you use a character variable as the argument to the DATALABEL= option, the plot will leave room for the maximum length. You can either change the length of the variable when it is created or I think you can add
format subsystem $10.;
after the PROC SGPLOT statement.
So it did turn out that it was the length of the data label that was causing the problem. I appreciate the quick responses.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
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.