Chapter Contents

Previous

Next
The GPLOT Procedure

PLOT Statement


Creates plots in which an independent variable is plotted on the horizontal axis and a dependent variable is plotted on the left vertical axis.

Requirements: At least one plot request is required.
Global statements: AXIS, FOOTNOTE, LEGEND, PATTERN, SYMBOL, TITLE
Supports: Drill-down functionality



Description

The PLOT statement specifies one or more plot requests that name the horizontal and left vertical axis variables, and optionally a third classification variable. This statement automatically

You can use statement options to manipulate the axes, modify the appearance of your graph, and describe catalog entries. You can use SYMBOL definitions to modify plot symbols for the data points, join data points, draw regression lines, plot confidence limits, or specify other types of interpolations. For more information on the SYMBOL statement, see About SYMBOL Definitions.

In addition, you can use global statements to modify the axes; add titles, footnotes, and notes to the plot; or modify the legend if one is generated by the plot. You can also use an Annotate data set to enhance the plot.

Syntax

PLOT plot-request(s) </option(s)>;

option(s) can be one or more options from any or all of the following categories:


Required Arguments

plot-request(s)
each specifies the variables to plot and produces a separate graph, unless you specify OVERLAY. All variables must be in the input data set. Multiple plot requests are separated with blanks. You can plot character or numeric variables. A plot request can be any of these:

y-variable*x-variable<=n>
plots the values of two variables and, optionally, assigns a SYMBOL definition to the plot.

y-variable
variable plotted on the left vertical axis.

x-variable
variable plotted on the horizontal axis.

n
number of the nth generated SYMBOL definition.

Note:   The nth generated SYMBOL definition is not necessarily the same as the nth SYMBOL statement. Plot requests of the form y-variable*x-variable=n assign the SYMBOL definition that is designated by n to the plot that is produced by y-variable*x-variable. See About Plot Requests that Assign a SYMBOL Definition for more information.  [cautionend]

(y-variable(s))*(x-variable(s))
plots the values of two or more variables and produces a separate graph for each combination of Y and X variables. That is, each Y*X pair is plotted on a separate set of axes, unless you specify OVERLAY.

y-variable(s)
variables plotted on the left vertical axes.

x-variable(s)
variables plotted on the horizontal axes.

If you use only one y-variable or only one x-variable, omit the parentheses for that variable, for example,

plot (temp rain)*month;

This plot request produces two plots, one of TEMP and MONTH and one of RAIN and MONTH.

y-variable*x-variable=third-variable
plots the values of two variables against a third classification variable

y-variable
variable plotted on the left vertical axis.

x-variable
variable plotted on the horizontal axis.

third-variable
classification variable against which y-variable and x-variable are plotted. Third-variable can be character or numeric, but numeric variables should contain discrete rather than continuous values, or should be formatted to provide discrete values.

A separate plot (set of data points) is produced for each unique value of third-variable; all plots are drawn on the same set of axes, and a legend is automatically generated to show the plot symbol and color for each value of the classification variable.

Note:   If a BY statement is used to produce multiple plots, you can make the legend the same across graphs by specifying the UNIFORM option in the PROC GPLOT statement.  [cautionend]

The following plot request produces a graph with a plot line for each department and a legend that shows the plot symbol for each department:

plot sales*weekday=dept;

For an example of a plot that specifies a third-variable, see Plotting Three Variables.

You can use more than one type of plot request in a single PLOT statement (provided that you do not specify OVERLAY), for example

plot temp*month rain*month=2;


Options

Options in a PLOT statement affect all graphs that are produced by that statement. You can specify as many options as you want and list them in any order.

ANNOTATE=Annotate-data-set
ANNO=Annotate-data-set
specifies a data set to annotate plots that are produced by the PLOT statement.
See also: The Annotate Data Set

AREAS=n
fills all the areas below plot line n with a pattern. The value of n specifies which areas to fill:

If you specify a value for AREAS= that is greater than the number of bounded areas in the plot, the area between the top plot line and the axis frame is filled.

Before an area can be filled, the data points that border the area must be joined by a line. Use a SYMBOL statement with one of these interpolation methods to join the data points:
INTERPOL=JOIN
INTERPOL=STEP
INTERPOL=Rseries
INTERPOL=SPLINE | SM | L

See SYMBOL Statement for details on interpolation methods.

By default, the AREAS= option fills areas by rotating a solid pattern through the colors list, starting with the first color in the list. If it needs more patterns, it rotates hatch patterns, beginning with the M2N0 pattern (see PATTERN Statement for more information on map/plot patterns). However, if the V6COMP graphics option is in effect, or if color is limited to a single color with the CPATTERN= or COLORS= graphic options, the solid pattern is skipped and the first default pattern is M2N0. If the COLORS= graphic option specifies a single color, use as many SYMBOL statements as you have areas to fill in the plot because the INTERPOL= setting does not automatically apply to multiple symbol definitions.

Note:   If your device's default colors list is in effect and the first color in the list is black, color rotation begins with the second color in the list (no solid black patterns), unless the V6COMP graphics option is in effect. See How Default Patterns and Outlines Are Generated for more information.  [cautionend]

You can alter the default pattern behavior by specifying patterns and colors on PATTERN statements that specify map and plot patterns. A separate PATTERN definition is needed for each specified area.

If you specify PATTERN statements, AREAS= uses the lowest numbered PATTERN statement first. If it runs out of patterns, it uses the default behavior for map and plot patterns (see PATTERN Statement for details).

Pattern definitions are assigned to the areas below the plot lines in the order the plots are drawn. The first area is that between the horizontal axis and the plot line that is drawn first. The second area is that above the first plot line and below the plot line that is drawn second, and so forth. If the line that is drawn second lies below the line that is drawn first, the second area is hidden when the first is filled. The plots with the lower line values must be drawn first to prevent one area fill from overlaying another. If the lines cross, only the part of an area that is above the previous line is visible.

Therefore, if you produce multiple plots by submitting multiple plot requests and using the OVERLAY option, the plot requests must be ordered in the PLOT statement so that the plot request that produces the lowest line values is the first (leftmost) plot request, the plot request that produces the next lowest line values is the second plot request, and so on.

If you produce multiple plots with a y-variable*x-variable=third-variable plot request, the lines are plotted in order of increasing third variable values. Therefore, the data must be recoded so that the lowest value of the third variable produces the lowest plot line, the next lowest value produces the next lowest plot line, and so on.

AREAS= works only if all plot lines are generated by the same PLOT or PLOT2 statement.

If you use the VALUE= option in the SYMBOL statement, some symbols may be hidden. If reference lines are also specified with AREAS=, they are drawn behind the pattern fill.
Featured in: Filling Areas in an Overlay Plot

AUTOHREF
draws reference lines at all major tick marks on the horizontal axis. If the AREAS= option is also used, the filled areas cover the reference lines. To draw lines on top of the filled areas, use the ANNOTATE= option in either the PROC GPLOT statement or the PLOT statement.

AUTOVREF
draws reference lines at all of the major tick marks on the vertical axis. If you also use the AREAS= option, the filled areas cover the reference lines. To draw lines on top of the filled areas, use the ANNOTATE= option in either the PROC GPLOT statement or the PLOT statement.

CAXIS=axis-color
CA=axis-color
specifies the color for the axis line and all major and minor tick marks. By default, the procedure uses the first color in the colors list.

If you use the CAXIS= option, it may be overridden by

Featured in: Connecting Plot Data Points

CFRAME=background-color
CFR=background-color
fills the axis area with the specified color. If the FRAME option is also in effect, the procedure determines the color of the frame according to the precedence list given later in the FRAME option description.

CHREF=reference-line-color
CH=reference-line-color
specifies the color for reference lines that are requested by the HREF= and AUTOHREF options. By default, these reference lines display in the color of the horizontal axis.

CTEXT=text-color
C=text-color
specifies the color for all text on the axes, including tick mark values and axis labels. If the PLOT request generates a legend, the CTEXT= option also colors the legend label and the value descriptions.

If you omit the CTEXT= option, a color specification is searched for in this order:

  1. the CTEXT= option in a GOPTIONS statement

  2. the default, the first color in the colors list.

If you use the CTEXT= option, it overrides the color specification for the axis label and the tick mark values in the COLOR= option in an AXIS definition that is assigned to the axis.

If you use the CTEXT= option, the color specification is overridden in one or more of these situations:

Featured in: Connecting Plot Data Points

CVREF=reference-line-color
CV=reference-line-color
specifies the color for reference lines that are requested by the VREF= and AUTOVREF options. By default, these reference lines display in the color of the vertical axis.
Featured in: Connecting Plot Data Points

DESCRIPTION='entry-description'
DES='entry-description'
specifies the description of the catalog entry for the plot. The maximum length for entry-description is 40 characters. The description does not appear on the plot. By default, the procedure assigns a description of the form PLOT OF y-variable*x-variable, where y-variable and x-variable are the names of the plot variables.

The entry-description can include the #BYLINE, #BYVAL, and #BYVAR substitution options, which work as they do when used on TITLE, FOOTNOTE, and NOTE statements. For more information, refer to the description of the options, and Substituting BY Line Values in a Text String. The 40-character limit applies before the substitution takes place for these options; thus, if in the SAS program the entry-description text exceeds 40 characters, it is truncated to 40 characters, and then the substitution is performed.

The descriptive text is shown in the "description" portion of each of the following:

FRAME | NOFRAME
FR | NOFR
specifies whether a frame is drawn around the axis area. The default is FRAME; however, if the V6COMP option is in effect on the GOPTIONS statement, the default is NOFRAME. If you also use a BUBBLE2 or PLOT2 statement and your plotting statements have conflicting frame specifications, FRAME is used.

For the frame color, a specification is searched for in this order:

  1. the CAXIS= option

  2. the COLOR= option in the AXIS definition assigned to the vertical axis

  3. the COLOR= option in the AXIS definition assigned to the horizontal axis

  4. the default, the first color in the colors list.

To fill the axis area with a background color, use the CFRAME= option.

GRID
draws reference lines at all major tick marks on both axes. You get the same result when you use all of these options in a PLOT statement: AUTOHREF, AUTOVREF, FRAME, LVREF=34, and LHREF=34. The line type for GRID is 34. The line color is the color of the axis.

HAXIS=value-list | AXIS<1 . . . 99>
specifies major tick mark values for the horizontal axis or assigns an axis definition. By default, the procedure scales the axis and provides an appropriate number of tick marks.

The way you specify value-list depends on the type of variable:

For a complete description of value-list, see the ORDER= option in the AXIS statement.

Note:   If data values fall outside of the range that is specified by the HAXIS= option, then by default the outlying data values are not used in interpolation calculations. See About the Input Data Set for more information on values out of range.  [cautionend]
Featured in: Plotting Two Variables, Connecting Plot Data Points, and Plotting with Different Scales of Values

HMINOR=number-of-minor-ticks
HM=number-of-minor-ticks
specifies the number of minor tick marks drawn between each major tick mark on the horizontal axis. Minor tick marks are not labeled. The HMINOR= option overrides the NUMBER= suboption of the MINOR= option in an AXIS definition. You must specify a positive number.
Featured in: Plotting Two Variables, Connecting Plot Data Points, and Plotting with Different Scales of Values

HREF=value-list
draws one or more reference lines perpendicular to the horizontal axis at points specified by value-list. See the HAXIS option for a description of value-list. If the AREAS= option is also used, the filled areas cover the reference lines. To draw lines on top of the filled areas, use the ANNOTATE= option on either the PROC GPLOT or the PLOT statement.
See also: CHREF= for a description of color specifications for reference lines

HTML=variable
identifies the variable in the input data set whose values create links in the HTML file created by the ODS HTML statement. These links are associated with the plot points, or if AREA= is used, with the areas between plot lines. The links point to the data or graph that you wish to display when the user drills down on the plot point or area.

HTML_LEGEND=variable
identifies the variable in the input data set whose values create links in the HTML file that is created by the ODS HTML statement. These links are associated with a legend value, and they point to the data or graph that you wish to display when the user drills down on the value. For information on creating graphs for the Output Delivery System, see Bringing SAS/GRAPH Output to the Web.

HZERO
specifies that tick marks on the horizontal axis begin in the first position with a value of zero. The HZERO request is ignored if negative values are present for the horizontal variable or if the horizontal axis has been specified with the HAXIS= option.

LEGEND | LEGEND=LEGEND<1...99>
generates a legend or specifies the legend to use for the plot.

If you use the SHAPE= option in a LEGEND statement, the value SYMBOL is valid. If you use the PLOT statement's AREAS= option, SHAPE=BAR is also valid.
See also: LEGEND Statement
Featured in: Generating an Overlay Plot

LHREF=line-type
LH=line-type
specifies the line type for drawing reference lines requested by the AUTOHREF or HREF= option. Line-type can be 1 through 46. By default, LHREF=1, a solid line. See Line Types for examples of available line types.

LVREF=line-type
LV=line-type
specifies the line type for drawing reference lines requested by the AUTOVREF or VREF= option. Line-type can be 1 through 46. By default, LVREF=1, a solid line. See Line Types for examples of available line types.
Featured in: Connecting Plot Data Points

NAME= 'entry-name'
specifies the name of the catalog entry for the graph. The maximum length for entry-name is eight characters. The default name is GPLOT. If the name that you specify duplicates the name of an existing entry, SAS/GRAPH software adds a number to the duplicate name to create a unique entry, for example, GPLOT1.

NOAXIS
NOAXES
suppresses the axes, including axis lines, axis labels, all major and minor tick marks, and tick mark values.

NOLEGEND
suppresses the legend that is generated by a plot request of the type y-variable*x-variable=third-variable.

OVERLAY
places all the plots that are generated by the PLOT statement on one set of axes. The axes are scaled to include the minimum and maximum values of all of the variables, and the variable names or labels associated with the first pair of variables label the axes.

The OVERLAY option produces a legend if you include the LEGEND or the LEGEND=n option in the PLOT statement.

You cannot use OVERLAY with plot requests of the form y-variable*x-variable=third-variable. However, you can achieve an overlay effect by using a PLOT and PLOT2 statement.
Featured in: Generating an Overlay Plot and Filling Areas in an Overlay Plot

REGEQN
displays the regression equation that is specified in the INTERPOL= option of the SYMBOL statement in the lower left hand corner of the plot. You cannot modify the format that is used for the equation.
Featured in: Plotting Two Variables

SKIPMISS
breaks a plot line or an area fill at occurrences of missing values of the Y variable. By default, plot lines and area fills are not broken at missing values. SKIPMISS is available only with join or spline interpolations. If SKIPMISS is used, observations should be sorted by the independent (horizontal axis) variable. If the plot request is y-variable*x-variable=third-variable, observations should also be sorted by the values of the third variable.
See also: About the Input Data Set for more information about values

VAXIS=value-list | AXIS<1...99>
specifies the major tick mark values for the vertical axis or assigns an AXIS definition. See the HAXIS option for a description of value-list.
Featured in: Plotting Two Variables and Connecting Plot Data Points

VMINOR=number-of-minor-ticks
VM=number-of-minor-ticks
specifies the number of minor tick marks that are drawn between each major tick mark on the vertical axis. Minor tick marks are not labeled. The VMINOR= option overrides the NUMBER= suboption of the MINOR= option in an AXIS definition. You must specify a positive number.
Featured in: Connecting Plot Data Points

VREF=value-list
draws one or more reference lines perpendicular to the vertical axis at points that are specified by value-list . See the HAXIS option for a description of value-list. If the AREAS= option is also used, the filled areas cover the reference lines. To draw lines on top of the filled areas, use the ANNOTATE= option in either the PROC GPLOT statement or the PLOT statement.
See also: CVREF= for a description of color specifications for reference lines
Featured in: Connecting Plot Data Points

VREVERSE
specifies that the order of the values on the vertical axis be reversed.

VZERO
specifies that tick marks on the vertical axis begin in the first position with a zero. The VZERO request is ignored if the vertical variable either contains negative values or has been ordered with the VAXIS= option or the ORDER= option in an AXIS statement.


Plot Requests with Multiple Variables

Plot requests with multiple variables produce a separate plot for every Y*X pair, unless you specify OVERLAY. For example, this statement produces four plots like those in Graphs Generated by Multiple Plot Requests (the actual plots are produced on separate pages):

plot (y b)*(x a);

Graphs Generated by Multiple Plot Requests

[IMAGE]


About SYMBOL Definitions

SYMBOL statements control the appearance of plot symbols and lines, and define interpolation methods. They can specify

SYMBOL definitions are assigned either by default by the GPLOT procedure or explicitly with a plot request.

If no SYMBOL definition is currently in effect, the GPLOT procedure produces a scatter plot of the data points using the default plot symbol, the plus sign (+). If you need more than one SYMBOL definition, the procedure rotates through the current colors list to produce symbols of different colors. If the current colors list contains only one color, or if all the colors are used, additional plot symbols are used.

If SYMBOL definitions have been defined but not explicitly assigned by a plot request of the form y-variable*x-variable=n, the procedure assigns them in the order in which they are generated. For example, this statement creates three plots:

plot y*x b*a s*r;

The procedure assigns the first generated SYMBOL definition to Y*X, the second generated SYMBOL definition to B*A, and the third to S*R.

If more SYMBOL definitions are needed than have been defined, the procedure uses the default definitions for the plots that remain.

See SYMBOL Statement for a complete discussion of the features of the SYMBOL statement.


About Plot Requests that Assign a SYMBOL Definition

Plot requests of the form y-variable*x-variable=n are useful when you use the OVERLAY option to produce multiple plots on one graph and you want to assign a particular SYMBOL definition to each plot.

With plot requests of this type it is important to remember that a single SYMBOL statement can generate multiple SYMBOL definitions, so that the SYMBOL definition that is designated by n may not be the same as the SYMBOL statement of the same number. That is, the third SYMBOL definition is not necessarily the same as the SYMBOL3 statement. See SYMBOL Statement for more information.


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.