SGPLOT Procedure

Concepts: SGPLOT Procedure

Plot Type Compatibility

There are four basic types of plots that you can create with the SGPLOT procedure.
Basic plots
scatter, series, step, band, bubble, high-low, needle, and vector plots
Fit and confidence plots
loess, regression, and penalized B-spline curves, and ellipses
Distribution plots
box plots, histograms, and normal and kernel density estimates
Categorization plots
dot plots, bar charts, line plots, and waterfall plots (preproduction)
Not all of the plot types can be used together in the same PROC SGPLOT step. The following table shows which of the plot types can be used together:
Plot Type Compatibility
Basic
Fit and Confidence
Distribution
Categorization
Basic
x
x
Fit and Confidence
x
x
Distribution
x
Categorization
x
Note: Box plots cannot be combined with any other plot types. Box plots can be overlaid with other box plots. However, overlaid box plots must have the same category variables.
If you submit a PROC SGPLOT step that combines two incompatible plot statements, then an error appears in the log.
The SGPLOT procedure draws the plots in your graph in the same order that you specify the plot statements. Because of this, it is important to consider the order of your plot statements so that your plots do not obscure one another. For example, if you specify a BAND statement after a SCATTER statement, then the band plot might obscure the markers in your scatter plot. You can also avoid obscuring your data by using the TRANSPARENCY= option to make your plots partially transparent.

Plot Axes

The SGPLOT procedure contains statements that enable you to change the type and appearance of your axes: XAXIS, X2AXIS, YAXIS, and Y2AXIS.
By default, the type of each axis is determined by the types of plots that use the axis and the data that is applied to the axis.
The SGPLOT procedure supports the following axis types:
Discrete
The axis contains independent data values rather than a range of numeric values. Each distinct value is represented by a tick mark. Discrete is the default axis type for character data.
Linear
The axis contains a linear range of numeric values. Linear is the default axis type for numeric data.
Logarithmic
The axis contains a logarithmic range of values. The logarithmic axis type is not used as a default.
Time
The axis contains a range of time values. Time is the default axis type for data that uses a SAS time, date, or datetime format.
Some types of plot do not support all of the axis types. For example, needle plots cannot use a discrete vertical axis. See the documentation for each plot statement to determine whether any axis type restrictions apply.

Legends in the SGPLOT Procedure

The SGPLOT procedure creates a legend automatically based on the plot statements and options that you specify. The automatic legend functionality determines which information is likely to be useful in the legend. You can override the automatic legend functionality by defining your own legend with the KEYLEGEND statement or by specifying the NOAUTOLEGEND option in the PROC SGPLOT statement.
You can create customized legends by using one or more KEYLEGEND statements. You can use the KEYLEGEND statement to control the contents, title, location, and border of the legend. See KEYLEGEND Statement.
You can specify the labels that represent your plots in the legend by using the LEGENDLABEL= option in the corresponding plot statements.

Automatic Differentiation of Visual Attributes

Depending on the plots and options that you specify, the SGPLOT procedure can automatically assign different style attributes to the plots in your graph. For example, if you specify two series plots, then each series plot automatically uses a different line color by default. If different attributes are not assigned by default, then you can force the procedure to use different style attributes by using the CYCLEATTRS option in the PROC SGPLOT statement. For example, you can use the CYCLEATTRS option to assign different colors to a series plot and a scatter plot. You can also disable automatic attribute differentiation by using the NOCYCLEATTRS option in the PROC SGPLOT statement.