Example Program and Statement Details

Example Graph

The following graph was generated by the Example Program:
Example Bubble Plot

Example Program

data bubbleintro;
input Engineer $ Salary number;
format Salary dollar7.0 number comma6.0;
datalines;
Electric 59000 89382
Civil 54000 73273
Software 56000 34833
Chemical 62000 25541
Mechanical 60000 19601
;
proc template;
  define statgraph engineer;
    begingraph;
      entrytitle 'Median Salary for Entry Level Engineers';
      entrytitle 'Bubbles Show Number of Engineers in Survey';
      layout overlay;
        bubbleplot x=engineer y=salary 
          size=number / datalabel=number; 
      endlayout;       
    endgraph;
  end;

proc sgrender data=bubbleintro template=engineer;
run;

Statement Summary

The BUBBLEPLOT statement displays one bubble for each row in the data, provided that row contains nonmissing values for X, Y, and SIZE. By default, the bubbles are displayed as filled, outlined circles. Regardless of the data order, the bubbles are always drawn from the largest size to the smallest size.
By default, the minimum and maximum values of the SIZE= column establish a range over which the bubble radii increase in linear proportion. The actual drawing size of the smallest and largest bubble is set automatically. You can adjust the smallest and largest bubble sizes with the BUBBLERADIUSMIN= and BUBBLERADIUSMAX= options. In these cases where the bubble sizes are proportional to each other, the default setting RELATIVESCALE=TRUE is appropriate.
If the SIZE= values are in the same units as the X and Y values, and both X and Y are numeric, you can generate a plot where the bubble-radius units match the axis-scale units. To do so, specify the BUBBLEPLOT statement within a LAYOUT OVERLAYEQUATED block, and in the BUBBLEPLOT statement, set RELATIVESCALE=FALSE.
Note: Within a LAYOUT OVERLAY, the unit-interval of the X and Y axes are not necessarily the same and the bubbles might be distorted into ellipses when RELATIVESCALE=FALSE. The OVERLAYEQUATED container ensures that the bubbles are displayed as circles, assuming that both the X= and Y= arguments specify numeric columns.
data influence;
input x y radius category;
datalines;
2  4 1 1
5  5 2 1
6  3 2 2
12 7 3 2
;
proc template;
  define statgraph equatedbubbles;
    begingraph;
      entrytitle 'Radius of Influence';
      entrytitle 'Bubbles Show Distance Covered by Observation';
      layout overlayequated /
          xaxisopts = (griddisplay=on)
          yaxisopts = (griddisplay=on);
        bubbleplot x=x y=y size=radius /
          group=category datatransparency=0.5
          relativescale=false ;
      endlayout;
    endgraph;
  end;

proc sgrender data=influence template=equatedbubbles;
run;
SIZE Values are in the same units as X and Y values

Required Arguments

X=column | expression
specifies the column for the X values of the bubble centers.
Y=column | expression
specifies the column for the Y values of the bubble centers.
SIZE=numeric-column | expression
specifies the bubble SIZE values.

Options

Statement Option
Description
Specifies the drawing size of largest bubble.
Specifies the drawing size of smallest bubble.
Specifies a style element to be used with the COLORRESPONSE= option.
Specifies a column that is used to map bubble colors to a continuous gradient.
Specifies a column for bubble labels.
Specifies the color and font attributes of the bubble labels.
Specifies the position of the bubble labels relative to the bubble.
Enhances the visual appearance of the filled bubbles.
Specifies the degree of the transparency of the bubble fills and bubble outlines.
Specifies whether to display outlined bubbles, filled bubbles, or outlined and filled bubbles.
Specifies the appearance of the filled bubble areas.
Creates a separate bubble color for each unique grouping that is specified.
Specifies whether missing values of the group variable are included in the plot.
Specifies indices for mapping bubble color and line attributes to one of the GraphData1–GranphDataN style elements.
Specifies a label for a legend.
Assigns a name to a plot statement for reference in other template statements.
Specifies the appearance of the bubble outlines.
Specifies that the data columns for this plot and the plot type be used for determining default axis features
Specifies whether the SIZE= column values are interpreted as relative values.
Specifies the type of scaling that is to be applied to the SIZE= column values.
Specifies whether to reverse the gradient (color ramp) that is defined by the COLORMODEL= option.
Specifies user-defined roles that can be used to display information in the tooltips.
Specifies a SIZE= column value threshold at which bubble size is clamped to the BUBBLERADIUSMAX= option value.
Specifies the information to display when the cursor is positioned over the bubbles.
Specifies display formats for information defined by the tooltip roles.
Specifies display labels for information defined by the tooltip roles.
Specifies an HTML page to display when a bubble is selected.
Specifies whether data are mapped to the primary X (bottom) axis or the secondary X2 (top) axis.
Specifies whether data are mapped to the primary Y (left) axis or to the secondary Y2 (right) axis.
BUBBLERADIUSMAX= dimension
specifies the drawing size of the largest bubble.
Default: Three times as large as the size set by GRAPHDATADEFULT:markerSize
Restriction: The BUBBLERADIUSMAX= value must be greater than the BUBBLERADIUSMIN= value.
Interaction: This option is ignored when RELATIVESCALE=FALSE.
Tip: A maximum size that is specified as a percent is interpreted as a percent of the graph's height. The height can be adjusted with the DESIGNHEIGHT= option in the BEGINGRAPH statement or the HEIGHT= option in the ODS GRAPHICS statement.
BUBBLERADIUSMIN= dimension
specifies the drawing size of the smallest bubble.
Default: GRAPHDATADEFULT:markerSize
Interaction: This option is ignored whenRELATIVESCALE= FALSE.
Restriction: The BUBBLERADIUSMIN= value must be less than the BUBBLERADIUSMAX= value.
Tip: A maximum size that is specified as a percent is interpreted as a percent of the graph's height. The height can be adjusted with the DESIGNHEIGHT= option in the BEGINGRAPH statement or the HEIGHT= option in the ODS GRAPHICS statement.
COLORMODEL= style-element
specifies a style element to be used with the COLORRESPONSE= option.
Default: The ThreeColorRamp style element for filled bubbles and ThreeColorAltRamp for unfilled bubbles.
style-element
name of a style element. The style element should contain these style attributes:
STARTCOLOR color for the smallest data value of the RESPONSECOLOR= variable
NEUTRALCOLOR color for the midpoint of the range of the REPONSECOLOR variable
ENDCOLOR color for the highest data value of the RESPONSECOLOR variable
Interaction: For this option to take effect, the COLORRESPONSE= option must also be specified.
Tip: To reverse the start and end colors of the ramp that is assigned to the color model, use the REVERSECOLORMODEL= option.
COLORRESPONSE= numeric-column | range-attr-var | expression
specifies a column that is used to map bubble colors to a continuous gradient. The gradient represents the range of unique response values.
range-attr-var
specifies a range attribute variable that is defined in a RANGEATTRVAR statement.
Restriction: A range attribute variable specification must be a direct reference to the attribute variable. It cannot be set by a dynamic variable.
Default:
  • If a numeric-column or an expression is specified, the color ramp that is specified by the COLORMODEL= option.
  • If a variable that is associated with a RANGEATTRVAR statement is specified, the color ramp is defined by the associated RANGEATTRMAP statement.
Interaction: If DISPLAY=(FILL OUTLINE), the bubble fill colors are assigned according to the gradient, but the bubble outlines are fixed according to the OUTLINEATTRS= settings.
If DISPLAY=(OUTLINE), the bubble outlines vary according to the gradient.
Interaction: The mapped color used for the bubbles is also used for the data labels.
Interaction: The GROUP= option is ignored if it is specified when this option is used.
DATALABEL= column | expression
specifies a column for bubble labels. The label positions are adjusted to prevent them from overlapping.
Default: no data labels are displayed
DATALABELATTRS=style-element | style-element (text-options) | (text-options)
specifies the color and font attributes of the bubble labels. See General Syntax for Attribute Options for the syntax on using a style-element and Text Options for available text-options.
Default:
  • For non-grouped data, the GraphDataText style element.
  • For grouped data, the text color is derived from the GraphData1–GraphDataN style elements. The data label color changes to match the group color derived from the ContrastColor attribute of the style element that is in effect.
Interaction: The default attributes are overridden if the COLORRESPONSE= option is used.
DATALABELPOSITION = TOPRIGHT | TOP | TOPLEFT | LEFT | CENTER | RIGHT | BOTTOMLEFT | BOTTOM | BOTTOMRIGHT
specifies the location of the bubble labels relative to the bubble.
Default: TOPRIGHT
DATASKIN= NONE | PRESSED | SHEEN | CRISP | GLOSS | MATTE
enhances the visual appearance of the filled bubbles.
Bubble Plots with Data Skins
Default: NONE
Requirement: For this option to have any effect, DISPLAY=FILL must be in effect. Otherwise, this option is ignored.
Interaction: The appearance of the data skin is based on the FILLATTRS= color.
Interaction: This option is ignored if the RELATIVESCALE= option is set to FALSE.
Interaction: When a data skin is applied, all bubble outlines are set by the skin, and the OUTLINEATTRS= option is ignored.
DATATRANSPARENCY=number
specifies the degree of the transparency of the bubble fills and bubble outlines.
Default: 0
Range: 0 (opaque) to 1 (entirely transparent)
Tip: The FILLATTRS= option can be used to set transparency for just the filled bubble areas. You can combine this option with FILLATTRS= to set one transparency for the bubble outlines but a different transparency for the bubble fills. Example:
datatransparency=0.2 fillattrs=(transparency=0.6)
DISPLAY=STANDARD | ALL | (display-options)
specifies whether to display outlined bubbles, filled bubbles, or outlined and filled bubbles.
Default: STANDARD
STANDARD
displays outlined, filled bubbles.
ALL
displays outlined, filled bubbles.
(display-options)
a list of options, enclosed in parentheses, that must include one of the following:
OUTLINE displays outlined bubbles.
FILL displays filled bubbles.
Tip: Use the DATASKIN=, OUTLINEATTRS=, and FILLATTRS= options to control the appearance of the bubbles.
FILLATTRS=style-element | style-element (fill-options) | (fill-options)
specifies the appearance of the filled bubble areas. See General Syntax for Attribute Options for the syntax on using a style-element and Fill Options for available fill-options.
Default:
  • For non-grouped data, the GraphDataDefault:Color style reference.
  • For grouped data, the Color attribute of GraphData1–GraphDataN style elements.
Interaction: For this option to have any effect, the fill must be enabled by the ODS style or the DISPLAY= option.
Interaction: When COLORRESPONSE= is in effect and the DISPLAY= option enables FILL display, the FILLATTRS= suboption COLOR= is ignored, and the bubble fill colors vary according to the gradient.
Tip: The DATATRANSPARENCY= option sets the transparency for the bubble fills and the bubble outlines. You can combine this option with DATATRANSPARENCY= to set one transparency for the outlines but a different transparency for the fills. Example:
datatransparency=0.2 fillattrs=(transparency=0.6)
GROUP=column | discrete-attr-var | expression
creates a separate bubble color for each unique grouping that is specified.
discrete-attr-var
specifies a discrete attribute variable that is defined in a DISCRETEATTRVAR statement.
Restriction: A discrete attribute variable specification must be a direct reference to the attribute variable. It cannot be set by a dynamic variable.
Default: No default. All bubbles have only one fill and one outline color as specified by the FILLATTRS= and OUTLINEATTRS options.
Interaction: When this option is used, the unique column values are found and then the bubble colors are taken from the following sources:
  • If a column or an expression is specified, the bubble attributes are derived from the GraphData1–GraphDataN style elements. If the bubbles are filled, then the COLOR attribute is used for bubble fill and the CONTRASTCOLOR attribute is used for the bubble outlines. If the bubbles are not filled, then the CONTRASTCOLOR and PATTERN are used for the bubble outlines.
  • If a variable that is associated with a DISCRETEATTRVAR statement is specified, the color mapping for the bubbles is defined by the associated DISCRETEATTRMAP statement.
Interaction: The mapped color that is used for outlines is also used as the color of the data labels.
Interaction: This option is ignored if the COLORRESPONSE= option is also used.
Interaction: The INCLUDEMISSINGGROUP option controls whether missing group values are considered a distinct group value.
See Also: The FILLATTRS= option.
INCLUDEMISSINGGROUP=boolean
specifies whether missing values of the group variable are included in the plot.
Default: TRUE
Interaction: For this option to take effect, the GROUP= option must also be specified.
Tip: Unless a discrete attribute map is in effect or the INDEX= option is used, the attributes of the missing group value are determined by the GraphMissing style element except when the MISSING= system option is used to specify a non-default missing character or when a user-defined format is applied to the missing group value. In those cases, the attributes of the missing group value are determined by a GraphData1–GraphDataN style element.
INDEX= numeric-column | expression
specifies indices for mapping bubble color and line attributes to one of the GraphData1–GraphDataN style elements.
Default: no default
Restriction: If the value of the numeric-column is missing or is less than 1, the observation is not used in the analysis. If the value is not an integer, only the integer portion is used.
Interaction:For this option to take effect, the GROUP= option must also be specified.
Interaction: All of the indexes for a specific group value must be the same. Otherwise, the results are unpredictable.
Interaction: The index values are 1-based indices. For the style definitions in GraphData1–GraphDataN, if the index value is greater than N, then a modulo operation remaps that index value to a number less than N to determine which style to use.
Interaction: If this option is not used, then the group values are mapped in the order of the data.
Discussion: Indexing can be used to collapse the number of groups that are represented in a graph. For more information, see Remapping Groups for Grouped Data.
LEGENDLABEL= "string"
specifies a label for the legend item that is associated with this plot.
Default: The string specified on the NAME= option.
Restriction: This option applies only to an associated DISCRETELEGEND statement.
Interaction: If the GROUP= option is specified, this option is ignored.
NAME= "string"
assigns a name to a plot statement for reference in other template statements.
Default: no default
Restriction: The string is case sensitive, cannot contain spaces, and must define a unique name within the template.
The specified name is used primarily in legend statements to coordinate the use of colors and line patterns between the graph and the legend.
OUTLINEATTRS=style-element | style-element (line-options) | (line-options)
specifies the appearance of the bubble outlines. See General Syntax for Attribute Options for the syntax on using a style-element and Line Options for available line-options.
Default:
  • For non-grouped data, the GraphOutlines style element.
  • For grouped data, unfilled bubbles use both the CONTRASTCOLOR and PATTERN attributes of the GraphData1–GraphDataN style elements. Filled bubbles use only the CONTRASTCOLOR attribute.
    If the COLORRESPONSE= option is specified and the bubbles are filled, then the outline attributes are derived from the GraphDataDefault style element. For unfilled bubbles, the outline colors vary according to the gradient.
Interaction: For this option to have any effect, outlines must be enabled by the ODS style or the DISPLAY= option.
Interaction: If the DATASKIN= option applies a data skin, this option is ignored.
Interaction: When the COLORRESPONSE= and DISPLAY=(OUTLINE) options are in effect, the OUTLINEATTRS= suboption COLOR= is ignored, and the bubble outline colors vary according to the gradient.
PRIMARY=boolean
specifies that the data columns for this plot and the plot type be used for determining default axis features.
Default: FALSE
Restriction: This option is ignored if the plot is placed under a GRIDDED or LATTICE layout block.
Details: This option is needed only when two or more plots within an overlay-type layout contribute to a common axis. For more information, see When Plots Share Data and a Common Axis
RELATIVESCALE=boolean
specifies whether the SIZE= column values are interpreted as relative values.
Default: TRUE
Interaction: When this option is set to TRUE, the BUBBLERADIUSMAX= and BUBBLERADIUSMIN= options can be used to fix the drawing size of the smallest bubble and largest bubble. If RELATIVESCALE=FALSE, the BUBBLERADIUSMAX= and BUBBLERADIUSMIN= options are ignored.
Interaction: If this option is set to FALSE, the DATASKIN= option is ignored.
Interaction: If either the X= argument or the Y= argument specifies categorical values, RELATIVESCALE=FALSE is ignored.
Details: Relative means that the size values do not translate directly into bubble radii. Rather, the bubble sizes are scaled to represent the value range of the SIZE= column.
For example, when RELATIVESCALE=TRUE, if only two bubbles are drawn with sizes of 2 and 4 they would appear the same as only two bubbles with sizes of 4000 and 8000. By contrast, when RELATIVESCALE=FALSE, the size values are interpreted in the same units as the axes.
If you set this option to FALSE, it is recommended that you also place the BUBBLEPLOT statement in a LAYOUT OVERLAYEQUATED container. This ensures that the X and Y axis units are the same. For more information, see Statement Summary.
RELATIVESCALETYPE=LINEAR | PROPORTIONAL
specifies the type of scaling that is to be applied to the SIZE= column values.
Note: This feature is for the second maintenance release of SAS 9.3 and later. See What's New in the SAS 9.3 Graph Template Language.
LINEAR
The size of the bubbles increases in linear proportion to the range of the SIZE= column values. For example, if only two bubbles are drawn with sizes of 2 and 4, they appear the same as only two bubbles with sizes of 4000 and 8000.
PROPORTIONAL
The size of each bubble is directly proportional to its corresponding SIZE= column value. For example, if only two bubbles are drawn with sizes of 50 and 100, the bubble for SIZE=50 is drawn to half the size of the bubble for SIZE=100.
Default: LINEAR
Interaction: This option is ignored when RELATIVESCALE=FALSE.
Interaction: When the SIZETHRESHOLDMAX= option is specified, for any SIZE= column value that is greater than the SIZETHRESHOLDMAX= value, the proportional scale is adjusted so that the size of the bubble for that value is clamped to the BUBBLERADIUSMAX= value.
Interaction: If all the values for the SIZE= column are negative, RELATIVESCALETYPE=PROPORTIONAL is ignored, and the default value is used.
Interaction: When RELATIVESCALETYPE=PROPORTIONAL is specified, the BUBBLERADIUSMIN= option specifies the minimum bubble size. In that case, when a SIZE= column value results in a bubble of a size that is less than the BUBBLERADIUSMIN= value, the bubble size for that value is changed to the BUBBLERADIUSMIN= value.
REVERSECOLORMODEL = boolean
specifies whether to reverse the gradient (color ramp) that is defined by either the ODS style that is in effect or by the COLORMODEL= option.
Default: FALSE
ROLENAME=(role-name-list)
specifies user-defined roles that can be used to display information in the tooltips. Columns for the tooltip display are specified in the TIP= option.
Default: no user-defined roles
(rolename-list)
a blank-separated list of rolename = column pairs.
For example, ROLENAME=(TIP1=POP_2009) assigns the data column POP_2009 to the user-defined role TIP1.
Requirement: The role names that you choose must be unique and different from the pre-defined roles X, Y , SIZE, GROUP, DATALABEL, and COLORRESPONSE .
Interaction: For this option to take effect, the TIP= option must also be used.
SIZETHRESHOLDMAX=numeric-value
specifies a SIZE= column value threshold at which bubble size is clamped to the BUBBLERADIUSMAX= option value. The size of the bubbles for all SIZE= column values that equal or exceed the specified threshold value is set to the BUBBLERADIUSMAX= value.
Note: This feature is for the second maintenance release of SAS 9.3 and later. See What's New in the SAS 9.3 Graph Template Language.
Default: The maximum SIZE= column value is mapped to the BUBBLERADIUSMAX= option value.
TIP=(role-list)
specifies the information to display when the cursor is positioned over the bubbles. If this option is used, it replaces all the information displayed by default. Roles for columns that do not contribute to the bubble plot can be specified along with roles that do.
Default: The columns assigned to these roles are automatically included in the tooltip information: X, Y , SIZE, GROUP, DATALABEL, and COLORRESPONSE.
(role-list)
an ordered, blank-separated list of unique BUBBLEPLOT and user-defined roles. BUBBLEPLOT roles include X, Y, SIZE, GROUP, DATALABEL, and COLORRESPONSE.
User-defined roles are defined with the ROLENAME= option.
The following example displays tooltips for the columns assigned to the roles X, Y, and SIZE, as well as the column POP_2009. The POP_2009 column is not assigned to any pre-defined BUBBLEPLOT role, so it must first be assigned a role:
  ROLENAME=(TIP1=POP_2009)
  TIP= (TIP1 X Y SIZE)
Requirement: To generate tooltips, you must include an ODS GRAPHICS ON statement that has the IMAGEMAP option specified, and write the graphs to the ODS HTML destination.
The labels and formats for the TIP variables can be controlled with theTIPLABEL= and TIPFORMAT= options.
TIPFORMAT=(role-format-list)
specifies display formats for information defined by the tooltip roles. Only the roles that appear in the TIP= option are used.
Default: The column format of the variable assigned to the role or BEST6. if no format is assigned to a numeric column.
(role-format-list)
a list of rolename = format pairs separated by blanks.
  ROLENAME=(TIP1=POP_2009)
  TIP=(TIP1 X Y SIZE)
  TIPFORMAT=(TIP1=comma12.) 
Requirement: Columns must be assigned to the roles for this option to have any effect. See the ROLENAME= option.
TIPLABEL=(role-label-list)
specifies display labels for information defined by the tooltip roles. Only the roles that appear in the TIP= option are used.
Default: The column label or column name of the variable assigned to the role.
(role-label-list)
a list of rolename = "string" pairs separated by blanks.
   ROLENAME=(TIP1=POP_2009) 
   TIP=(TIP1 X Y SIZE)
   TIPLABEL=(TIP1="Population in 2009")
Requirement: Columns must be assigned to the roles for this option to have any effect. See the ROLENAME= option.
URL=character-column
specifies an HTML page to display when a bubble is selected.
Default: no default
character-column
each value of the column must be a valid HTML page reference (HREF). For example, http://www.sas.com/technologies/analytics/index.html is a valid reference.
Requirement: To generate a plot with selectable bubbles, you must include an ODS GRAPHICS ON statement that has the IMAGEMAP option specified, and write the graphs to the ODS HTML destination.
The URL value can be blank for some X and Y pairs, meaning that no action is taken when the corresponding point is selected. The URL value can be the same for any X and Y pairs. In that case, the same action is taken when the bubbles for those X and Y pairs are selected.
XAXIS=X | X2
specifies whether data are mapped to the primary X (bottom) axis or to the secondary X2 (top) axis.
Default: X
Interaction: The overall plot specification and the layout type determine the axis display for the specified axis. For more information, see How Axis Features Are Determined.
YAXIS=Y | Y2
specifies whether data are mapped to the primary Y (left) axis or to the secondary Y2 (right) axis.
Default: Y
Interaction: The overall plot specification and the layout type determine the axis display for the specified axis. For more information, see How Axis Features Are Determined.