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 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 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 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 layout. For more information about how child positions are determined in an overlay-type layout, see the LAYOUT OVERLAY’s Example Program and Statement Details.
Default: NONE
NONE
Do not automatically align the legend within its parent layout. The legend’s position is set by the HALIGN= and VALIGN= options.
AUTO
Available only if the parent layout contains a scatter plot; ignored otherwise. Within the parent layout, attempt to center the legend in the area that is farthest from any surrounding data point markers.
(location-list)
Within the parent layout, restrict the legend’s possible locations to those locations in the specified location-list, and use 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.
HALIGN= RIGHT | CENTER | LEFT
specifies the horizontal alignment of the legend within its parent layout when nested within an overlay-type layout. For more information about how child positions are determined in an overlay-type layout, see the LAYOUT OVERLAY’s Example Program and Statement Details.
Default: RIGHT if LOCATION=OUTSIDE CENTER if LOCATION=INSIDE
Restriction: If LOCATION=OUTSIDE, the HALIGN= and VALIGN= options cannot both be set to CENTER.
Restriction: This option is available only when this statement is nested within an overlay-type layout. It is ignored if the parent layout is not an overlay-type layout.
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: 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
specifies the vertical alignment of the legend within its parent layout when nested within an overlay-type layout. For more information about how child positions are determined in an overlay-type layout, see the LAYOUT OVERLAY’s Example Program and Statement Details.
Default: CENTER
Restriction: If LOCATION=OUTSIDE, the VALIGN= and HALIGN= options cannot both be set to CENTER.
Restriction: This option is available only when this statement is nested within an overlay-type layout. It is ignored if the parent layout is not an overlay-type layout.
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.