Example Program and Statement Details

Example Graph

The following graph was generated by the Example Program:
Graph with a Continuous Legend

Example Program

proc template;
  define statgraph continuouslegend;
    begingraph;
      entrytitle "Height and Weight Distribution";
        layout overlay;
          scatterplot x=height y=weight /
            markercolorgradient=density
            markerattrs=(symbol=squarefilled size=6px)
            name="scatter";
          continuouslegend "scatter" / orient=vertical
            location=outside valign=center halign=right
            valuecounthint=10 title="Density";
        endlayout;
    endgraph;
  end;
run;
proc sgrender data=sashelp.gridded(where=(count>0))
  template=continuouslegend;
run;

Statement Summary

A continuous legend consists of a color ramp and a numeric scale indicating color values.
In the following figure, the continuous legend references a contour plot with a fixed number of levels. The color ramp and legend values automatically reflect these discrete levels. The legend options VALUECOUNT= and VALUECOUNTHINT= have no effect.
Continuous Legend Representing Discrete Data Levels
In this next figure, the continuous legend references a contour plot with a continuous gradient. The number of legend values displayed is automatically determined by the legend, or decided by the contributing plot, such as the CONTOURPLOTPARM with CONTOURTYPE=FILL. For plots with a continuous gradient, you can use the legend options VALUECOUNT= or VALUECOUNTHINT= to control how many legend values appear. (These options are ignored if there is no gradient.)
Controlling Legend Values on a Gradient Legend
Within an overlay-type layout, when a continuous legend is placed inside the plot area with LOCATION=INSIDE,
  • It is always placed on top of plot lines and markers.
  • By default, its background is fully transparent (OPAQUE=FALSE), meaning that underlying lines, markers, and data labels show through the legend.
  • Its position can be controlled with the AUTOALIGN= option, or with the HALIGN= and VALIGN= options.
Within an overlay-type layout, when a continuous legend is placed outside the plot area with LOCATION=OUTSIDE,
  • By default, its background is fully opaque (OPAQUE=TRUE).
  • Its position can be controlled with the HALIGN= and VALIGN= options.

Required Argument

"graph-name"
specifies the plot to be represented by the legend. The plot is identified by the name that is assigned to it on the plot statement’s NAME= option.
Requirement: graph-name must be enclosed in quotation marks.
Note: Unlike the DISCRETELEGEND statement, only a single graph-name can be specified.

Options

Statement Option
Description
Specifies whether the legend is automatically aligned within its parent layout when nested within an overlay-type or region layout.
Specifies the color of the legend background.
Specifies whether a border is displayed around the legend.
Specifies the properties of the border line around the legend.
specifies the horizontal alignment of the legend within its parent layout when nested within an overlay-type or region layout.
Specifies whether the legend appears inside or outside the plot area.
Specifies whether the legend background is opaque.
Specifies the orientation of the legend.
Specifies the amount of extra space that is added inside the legend perimeter.
Specifies the title of the legend.
Specifies the color and font attributes of the legend title.
Specifies the vertical alignment of the legend within its parent layout when nested within an overlay-type or region layout.
Specifies the color and font attributes of the legend values.
Specifies the number of values that the continuous legend must use to label the data range. Available only for plots that display a gradient.
Recommends a number of values for the continuous legend to use to label the data range. Available only for plots that display a gradient.
AUTOALIGN=NONE | AUTO | (location-list)
specifies whether the legend is automatically aligned within its parent layout when nested within an overlay-type or region layout. For more information about how child positions are determined in an overlay-type layout, see the LAYOUT OVERLAY’s Statement Summary.
Default: NONE
NONE
does not automatically align the legend within its parent layout. The legend’s position is set by the HALIGN= and VALIGN= options.
AUTO
centers the legend in the area that is farthest from any surrounding data point markers within the parent layout. Available only if the parent layout contains a scatter plot; ignored otherwise.
(location-list)
within the parent layout, restricts the legend’s possible locations to those locations in the specified location-list, and uses the location-list position that least collides with the parent layout’s other graphics features. The location-list is blank-separated and can contain any of these locations: TOPLEFT, TOP, TOPRIGHT, LEFT, CENTER, RIGHT, BOTTOMLEFT, BOTTOM, and BOTTOMRIGHT.
Interaction: This option has no effect unless LOCATION=INSIDE.
Interaction: If LOCATION=INSIDE, this option overrides HALIGN= and VALIGN=.
BACKGROUNDCOLOR=style-reference | color
specifies the color of the legend background.
Default: The GraphLegendBackground:Color style reference.
style-reference
a reference of the form style-element:style-attribute. Only the style-attribute named COLOR is used.
Interaction: OPAQUE=TRUE must be in effect for the color to be seen. By default, OPAQUE=FALSE.
BORDER=boolean
specifies whether a border is displayed around the legend.
Default: FALSE
BORDERATTRS=style-element | style-element (line-options) | (line-options)
specifies the attributes of the border line around the legend. See General Syntax for Attribute Options for the syntax on using a style-element and Line Options for available line-options.
Default: The GraphBorderLines style element.
Interaction: BORDER=TRUE must be set for this option to have any effect.
Tip: The color of the frame around the color ramp and the color ramp tick lines is controlled by the GraphAxisLines:contrastcolor style element.
HALIGN= RIGHT | CENTER | LEFT | number
specifies the horizontal alignment of the legend within its parent layout when nested within an overlay-type or region layout. For more information about how child positions are determined in an overlay-type or region layout, see the LAYOUT OVERLAY’s Statement Summary.
Default: RIGHT if LOCATION=OUTSIDE. CENTER if LOCATION=INSIDE
Range: A number specification can range from 0 to 1. The number represents a fraction of the parent container’s width, where 0 is all the way to the left and 1 is all the way to the right.
Restriction: This option is available only when this statement is nested within an overlay-type or region layout. It is ignored if the parent layout is not an overlay-type or region layout.
Interaction: If LOCATION=OUTSIDE, the HALIGN= and VALIGN= options cannot both be set to CENTER.
Interaction: For a number setting to take effect, LOCATION=INSIDE must be set. A number setting is invalid on this option when LOCATION=OUTSIDE.
Interaction: If LOCATION=INSIDE and the AUTOALIGN= option is enabled, this option is ignored.
LOCATION=OUTSIDE | INSIDE
specifies whether the legend appears inside or outside the plot area.
Default: OUTSIDE
Restriction: This option has effect only when the CONTINUOUSLEGEND statement appears within a 2-D overlay-type layout and there is at least one stand-alone plot statement with XY axes that is referenced by the legend. For more information about how child positions are determined in an overlay-type layout, see the LAYOUT OVERLAY’s Example Program and Statement Details.
Interaction: The actual position is determined by the settings for the LOCATION=, AUTOALIGN=, HALIGN= , and VALIGN= options.
Interaction: If this option is set to OUTSIDE, the HALIGN= and VALIGN= options must specify a keyword (LEFT, RIGHT, or CENTER). The number setting for the alignment is invalid when the legend is positioned outside of the plot area.
Interaction: Within an overlay-type layout, if the ORIENT= option is not set, the orientation changes depending on the actual position. If LOCATION=OUTSIDE and the legend is right or left of the plot, the orientation is vertical. If LOCATION=OUTSIDE and the legend is above or below the plot, the orientation is horizontal.
OPAQUE=boolean
specifies whether the legend background is opaque (TRUE) or transparent (FALSE).
Default: FALSE
Interaction: When this option is set to FALSE, the background color is not used.
ORIENT=VERTICAL | HORIZONTAL
specifies the orientation of the legend.
Default: VERTICAL
PAD=dimension | (pad-options)
specifies the amount of extra space that is reserved inside the legend perimeter.
Default: The default padding for all sides is 0. Values without units are in pixels (px). A unit must be provided if other than pixels.
dimension
specifies a dimension to use for the extra space at the left, right, top, and bottom of the legend perimeter.
(pad-options)
enables separate settings for the left, right, top, and bottom padding dimensions. Use the pad-options to create non-uniform padding. These options must be enclosed in parentheses. Each option is specified as a name = value pair. Sides not assigned padding are padded with the default amount.
Values without units are in pixels (px). A unit must be provided if other than pixels.
LEFT=dimension specifies the amount of extra space added to the left side.
RIGHT=dimension specifies the amount of extra space added to the right side.
TOP=dimension specifies the amount of extra space added to the top.
BOTTOM=dimension specifies the amount of extra space added to the bottom.
TITLE= "string"
specifies the title of the legend.
Default: no default
Requirement: string must be enclosed in quotation marks.
TITLEATTRS=style-element | style-element (text-options) | (text-options)
specifies the color and font attributes of the legend title. See General Syntax for Attribute Options for the syntax on using a style-element and Text Options for available text-options.
Default: The GraphLabelText style element.
Interaction: For this option to have any effect, the TITLE= option must also be specified.
VALIGN=CENTER | TOP | BOTTOM | number
specifies the vertical alignment of the legend within its parent layout when nested within an overlay-type or region layout. For more information about how child positions are determined in an overlay-type or region layout, see the LAYOUT OVERLAY’s Statement Summary.
Default: CENTER
Range: A number specification can range from 0 to 1. The number represents a fraction of the parent container’s height, where 0 is on the bottom and 1 is on the top.
Restriction: This option is available only when this statement is nested within an overlay-type or region layout. It is ignored if the parent layout is not an overlay-type or region layout.
Interaction: If LOCATION=OUTSIDE, the VALIGN= and HALIGN= options cannot both be set to CENTER.
Interaction: For a number setting to take effect, LOCATION=INSIDE must be set. A number setting is invalid on this option when LOCATION=OUTSIDE.
Interaction: If LOCATION=INSIDE and the AUTOALIGN= option is enabled, this option is ignored.
VALUEATTRS=style-element | style-element (text-options) | (text-options)
specifies the color and font attributes of the legend values. See General Syntax for Attribute Options for the syntax on using a style-element and Text Options for available text-options.
Default: The GraphValueText style element.
VALUECOUNT=positive-integer
specifies the number of values that the continuous legend must use to label the data range.
Default: The VALUECOUNTHINT= setting is used.
Restriction: The associated plot must be displayed with smooth gradient for this option to have any effect. For example, in a contour plot, CONTOURTYPE must be set to GRADIENT or LINEGRADIENT.
The legend uses even intervals to label the range.
VALUECOUNTHINT=positive-integer
recommends a number of values for the continuous legend to use to label the data range.
Default: 6
Restriction: The associated plot must be displayed with smooth gradient for this option to have any effect. For example, in a contour plot, CONTOURTYPE must be set to GRADIENT or LINEGRADIENT.
The legend uses even intervals to label the range.