Chapter Contents |
Previous |
Next |
The PLOT Procedure |
Tip: | You can use multiple PLOT statements. |
PLOT plot-request(s) </ option(s)>; |
To do this | Use this option | |
---|---|---|
Control the axes | ||
Specify the tick-mark values | HAXIS= and VAXIS= | |
Expand the axis | HEXPAND and VEXPAND | |
Specify the number of print positions | HPOS= and VPOS= |
|
Reverse the order of the values | HREVERSE and VREVERSE | |
Specify the number of print positions between tick marks | HSPACE= and VSPACE= | |
Assign a value of zero to the first tick mark | HZERO and VZERO |
|
Specify reference lines | ||
Draw a line perpendicular to the specified values on the axis | HREF= and VREF= |
|
Specify a character to use to draw the reference line | HREFCHAR= and VREFCHAR= | |
Put a box around the plot | BOX | |
Overlay plots | OVERLAY | |
Produce a contour plot | ||
Draw a contour plot | CONTOUR | |
Specify the plotting symbol for one contour level | Scontour-level= | |
Specify the plotting symbol for multiple contour levels | SLIST= | |
Label points on a plot | ||
List the penalty and the placement state of the points | LIST= | |
Force the labels away from the origin | OUTWARD= | |
Change default penalties | PENALTIES= | |
Specify locations for the placement of the labels | PLACEMENT= | |
Specify a split character for the label | SPLIT= | |
List all placement states in effect | STATES |
Required Arguments |
Each form of plot-request(s) supports a label variable. A label variable is preceded by a dollar sign ($) and specifies a variable whose values label the points on the plot. For example,
plot y*x $ label-variable plot y*x='*' $ label-variable
See Labeling Plot Points with Values of a Variable for more information. In addition, see Adding Labels to a Plot and all the examples that follow it.
The plot-request(s) can be one or more of the following:
For example, the following statement requests a plot of Y by X:
plot y*x;
Y appears on the vertical axis, X on the horizontal axis.
This form of the plot request uses the default method of choosing a plotting symbol to mark plot points. When a point on the plot represents the values of one observation in the data set, PROC PLOT puts the character A at that point. When a point represents the values of two observations, the character B appears. When a point represents values of three observations, the character C appears, and so on through the alphabet. The character Z is used for the occurrence of 26 or more observations at the same printing position.
For example, the following statement requests a plot of Y by X, with each point on the plot represented by a plus sign (+):
plot y*x='+';
FEMALE
and
MALE
: the values
F
and
M
mark each observation on the plot.
plot height*weight=gender;
Specifying Variable Lists in Plot Requests |
Plot request | What is plotted |
(a - - d) |
a*b a*c a*d b*c b*d c*d |
(x1 - x4) |
x1*x2 x1*x3 x1*x4 x2*x3 x2*x4 x3*x4 |
(_numeric_) |
All combinations of numeric variables |
y*(x1 - x4) |
y*x1 y*x2 y*x4 y*x4 |
If both the vertical and horizontal specifications request more than one variable and a variable appears in both lists, it will not be plotted against itself. For example, the following statement does not plot B*B and C*C:
plot (a b c)*(b c d);
Specifying Combinations of Variables |
plot (y1-y2) * (x1-x2); plot y1*x1 y1*x2 y2*x1 y2*x2;
A colon combines the variables pairwise. Thus, the first variables of each list combine to request a plot, as do the second, third, and so on. For example, the following plot requests are equivalent:
plot (y1-y2) : (x1-x2); plot y1*x1 y2*x2;
Options |
Featured in: | Overlaying Two Plots |
When you use CONTOUR, PROC PLOT does not plot observations with missing values for variable.
Overprinting, if it is allowed by the OVP system option, is used to produce the shading. Otherwise, single characters varying in darkness are used. The CONTOUR option is most effective when the plot is dense.
Default: | 10 |
Range: | 1-10 |
Featured in: | Producing a Contour Plot |
n <...n> |
BY increment |
n TO n BY increment |
The values must be in either ascending or descending order. Use a negative value for increment to specify descending order. The specified values are spaced evenly along the horizontal axis even if the values are not uniformly distributed. Numeric values can be specified in the following ways:
HAXIS= value | Comments |
---|---|
10 to 100 by 5 |
Values appear in increments of 5, starting at 10 and ending at 100. |
by 5 |
Values are incremented by 5. PROC PLOT determines the minimum and maximum values for the tick marks. |
10 100 1000 10000 |
Values are not uniformly distributed. This specification produces a logarithmic plot. If PROC PLOT cannot determine the function implied by the axis specification, it uses simple linear interpolation between the points. To determine whether PROC PLOT correctly interpolates a function, you can use the DATA step to generate data that determines the function and see whether it appears linear when plotted. See Plotting Data on a Logarithmic Scale for an example. |
1 2 10 to 100 by 5 |
A combination of the previous specifications. |
'value-1' <...'value-n'> |
For example,
haxis='Paris' 'London' 'Tokyo'
The character strings are case-sensitive. If a character variable has an associated format, axis-specification must specify the formatted value. The values can appear in any order.
'date-time-value'i <...'date-time-value'i> |
'date-time-value'i TO
<...'date-time-value'i>
<BY increment> |
D | date |
T | time |
DT | datetime |
DAY | |
WEEK | |
MONTH | |
QTR | |
YEAR |
For datetimes, increment can be one of the following:
DTDAY | |
DTWEEK | |
DTMONTH | |
DTQTR | |
DTYEAR |
For times, increment can be one of the following:
HOUR | |
MINUTE | |
SECOND |
For example,
haxis='01JAN95'd to '01JAN96'd by month haxis='01JAN95'd to '01JAN96'd by qtr
Note: You must use a FORMAT statement to print the tick-mark values
in an understandable form.
Interaction: | You can use the HAXIS= and VAXIS= options with the VTOH= option to equate axes. If your data are suitable, use HAXIS=BY n and VAXIS=BY n with the same value for n and specify a value for the VTOH= option. The number of columns separating the horizontal tick marks is nearly equal to the number of lines separating the vertical tick marks times the value of the VTOH= option. In some cases, PROC PLOT cannot simultaneously use all three values and changes one or more of the values. |
Featured in: | Controlling the Horizontal Axis and Adding a Reference Line , Plotting Data on a Logarithmic Scale , and Plotting Date Values on an Axis |
HEXPAND causes PROC PLOT to ignore information about the spacing of the data. Plots produced with this option waste less space but may obscure the nature of the relationship between the variables.
For the syntax for value-specification, see HAXIS= .
Featured in: | Plotting BY Groups |
Default: | vertical bar (|) |
See also: | FORMCHAR= option and HREF= |
Interaction: | PROC PLOT ignores HZERO if the horizontal variable has negative values or if the HAXIS= option specifies a range that does not begin with zero. |
Tip: | LIST is equivalent to LIST=0. |
See also: | Understanding Penalties |
Featured in: | Adjusting Labels on a Plot with the PLACEMENT= Option |
Tip: | This option is useful only when you are labeling points with the values of a variable. |
When the SAS system option OVP is in effect and overprinting is allowed, the plots are superimposed; otherwise, when NOOVP is in effect, PROC PLOT uses the plotting symbol from the first plot to represent points appearing in more than one plot. In such a case, the output includes a message telling you how many observations are hidden.
Featured in: | Overlaying Two Plots |
value TO value
See also: | Understanding Penalties |
Featured in: | Changing a Default Penalty |
Use the following suboptions to control the placement:
place=(h=0 1 -1 2 -2)
You can use the keywords BY ALT in this list. BY ALT produces a series of numbers whose signs alternate between positive and negative and whose absolute values change by one after each pair. For instance, the following PLACE= specifications are equivalent:
place=(h=0 -1 to -3 by alt) place=(h=0 -1 1 -2 2 -3 3)
If the series includes zero, the zero appears twice. For example, the following PLACE= options are equivalent:
place=(h= 0 to 2 by alt) place=(h=0 0 1 -1 2 -2)
Default: | H=0 |
Range: | -500 to 500 |
Default: | L=1 |
Range: | 1-200 |
Default: | CENTER |
A new expression begins when a suboption is not preceded by an operator. Parentheses around each expression are optional. They make it easier to recognize individual expressions in the list. However, the entire expression list must be in parentheses, as shown in the following example. Expanding an Expression List into Placement States shows how this expression is expanded and describes each placement state.
place=((v=1) (s=right left : h=2 -2) (v=-1) (h=0 1 to 2 by alt * v=1 -1) (l=1 to 3 * v=1 to 2 by alt * h=0 1 to 2 by alt))
Each combination of values is a placement state. The procedure uses the placement states in the order in which they appear in the placement states list, so specify your most preferred placements first. For each label, the procedure tries all states, then uses the first state that places the label with minimum penalty. Once all labels are initially placed, the procedure cycles through the plot multiple times, systematically refining the placements. The refinement step tries to both minimize the penalties and to use placements nearer to the beginning of the states list. However, PROC PLOT uses a heuristic approach for placements, so the procedure does not always find the best set of placements.
Alias: | PLACE= |
Defaults: | There are two defaults for the PLACE= option. If you are using a blank as your plotting symbol, the default placement state is PLACE=(S=CENTER : V=0 : H=0 : L=1), which centers the label. If you are using anything other than a blank, the default is PLACE=((S=RIGHT LEFT : H=2 -2) (V=1 -1 * H=0 1 -1 2 -2)). The default for labels placed with symbols includes multiple positions around the plotting symbol so the procedure has flexibility when placing labels on a crowded plot. |
Tip: | Use the STATES option to print a list of placement states. |
See also: | Labeling Plot Points with Values of a Variable |
Featured in: | Adjusting Labels on a Plot with the PLACEMENT= Option and Adjusting Labeling on a Plot with a Macro |
Expression | Placement state | Meaning | |
---|---|---|---|
(V=1) | S=CENTER L=1 H=0 V=1 | Center the label, relative to the point, on the line above the point. Use one line for the label. | |
(S=RIGHT LEFT : H=2 -2) | S=RIGHT L=1 H=2 V=0 | Begin the label in the second column to the right of the point. Use one line for the label. | |
S=LEFT L=1 H=-2 V=0 | End the label in the second column to the left of the point. Use one line for the label. | ||
(V=-1) | S=CENTER L=1 H=0 V=- 1 | Center the label, relative to the point, on the line below the point. Use one line for the label. | |
(H=0 1 to 2 BY ALT * V=1 -1) | S=CENTER L=1 H=0 V=1 | Center the label, relative to the point, on the line above the point. | |
S=CENTER L=1 H=0 V=-1 | Center the label, relative to the point, on the line below the point. | ||
S=CENTER L=1 H=1 V=1 | From center, shift the label one column to the right on the line above the point. | ||
S=CENTER L=1 H=1 V=-1 | From center, shift the label one column to the right on the line below the point. | ||
S=CENTER L=1 H=-1 V=1 | From center, shift the label one column to the left on the line above the point. | ||
S=CENTER L=1 H=- 1 V=-1 | From center, shift the label one column to the left on the line below the point. | ||
S=CENTER L=1 H=2 V=1 S=CENTER L=1 H=2 V=-1 | From center, shift the labels two columns to the right, first on the line above the point, then on the line below. | ||
S=CENTER L=1 H=-2 V=1 S=CENTER L=1 H=-2 V=-1 |
From center, shift the labels two columns to the left, first on the line above the point, then on the line below. | ||
(L=1 to 3 * V=1 to 2 BY ALT * H=0 1 to 2 BY ALT) | S=CENTER L=1 H=0 V=1 | Center the label, relative to the point, on the line above the point. Use one line for the label. | |
S=CENTER L=1 H=1 V=1 S=CENTER L=1 H=-1 V=1 S=CENTER L=1 H=2 V=1 S=CENTER L=1 H=-2 V=1 | From center, shift the label one or two columns to the right or left on the line above the point. Use one line for the label. | ||
S=CENTER L=1 H=0 V=-1 | Center the label, relative to the point, on the line below the point. Use one line for the label. | ||
S=CENTER L=1 H=1 V=-1 S=CENTER L=1 H=-1 V=-1 S=CENTER L=1 H=2 V=-1 S=CENTER L=1 H=-2 V=-1 | From center, shift the label one or two columns to the right and the left on the line below the point. | ||
. | |||
. | |||
. | Use the same horizontal shifts on the line two lines above the point and on the line two lines below the point. | ||
S=CENTER L=1 H=- 2 V=-2 | |||
S=CENTER L=2 H=0 V=1 | Repeat the whole process splitting the label over two lines. Then repeat it splitting the label over three lines. | ||
. | |||
. | |||
. | |||
S=CENTER L=3 H=- 2 V=-2 |
For example, to specify three levels of shading for the Z variable, use the following statement:
plot y*x=z / contour=3 s1='A' s2='+' s3='X0A';
You can also specify the plotting symbols as hexadecimal constants:
plot y*x=z / contour=3 s1='7A'x s2='7F'x s3='A6'x;
This feature was designed especially for printers where the hex constants can represent grey-scale fill characters.
Range: | 1 to the highest contour level (determined by the CONTOUR option). |
See also: | SLIST= and CONTOUR |
plot y*x=z / contour=5 slist='.' ':' '!' '=' '+O';
Default: | If you omit a plotting symbol for each
contour level, PROC PLOT uses the default symbols:
slist='.' ',' '-' '=' '+' 'O' 'X' 'W' '*' '#' |
Restriction: | If you use the SLIST= option, it must be listed last in the PLOT statement. |
See also: | Scontour-level= and CONTOUR= |
PROC PLOT shifts split labels as a block, not as individual fragments
(a fragment is the part of the split label that is contained
on one line). For example, to force
This is a label
to split after the
a
, change it to
This is a*label
and specify SPLIT='
*
'.
See also: | Labeling Plot Points with Values of a Variable |
Featured in: | Producing a Contour Plot and Adjusting Labeling on a Plot with a Macro |
See also: | HEXPAND |
See also: | HPOS= |
Featured in: | Controlling the Horizontal Axis and Adding a Reference Line |
Default: | horizontal bar (-) |
See also: | FORMCHAR= option , HREFCHAR= , and VREF= |
Interaction: | PROC PLOT ignores the VZERO option if the vertical variable has negative values or if the VAXIS= option specifies a range that does not begin with zero. |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.