Plotting the Relationship between Variables |
Specifying the Axes Labels |
Sometimes you might want to supply additional information about the axes. You can enhance the plot by specifying the labels for the vertical and horizontal axes.
The following program plots the log transformation of DowJonesHigh for each year and uses the LABEL statement to change the axes labels:
options pagesize=40 linesize=76 pageno=1 nodate; proc plot data=highlow; plot LogDowHigh*Year; label LogDowHigh='Log of Highest Value' Year='Year Occurred'; title 'Dow Jones Industrial Average Yearly High'; run;
The following output shows the plot:
Specifying the Labels for the Axes
Dow Jones Industrial Average Yearly High 1 Plot of LogDowHigh*Year. Legend: A = 1 obs, B = 2 obs, etc. | 10.00 + | | | L | o | g | A 9.00 + A o | A f | | A H | i | AA g | A h 8.00 + AAA e | A s | A t | A | V | A a | AA l 7.00 + AA AA u | AAAAAA A A AAAAA e | A A | AAAAA | A | AA | A 6.00 + A ---+---------+---------+---------+---------+---------+-- 1950 1960 1970 1980 1990 2000 Year OccurredPlotting the log transformation of DowJonesHigh changes the exponential trend to a linear trend. The label for each variable is centered parallel to its axis.
Specifying the Tick Marks Values |
In the previous plots, the range on the horizontal axis is from 1950 to 2000. Tick marks and labels representing the years are spaced at intervals of 10. You can control the selection of the range and the interval on the horizontal axis with the HAXIS= option in the PLOT statement. A corresponding PLOT statement option, VAXIS=, controls the values of the tick mark on the vertical axis.
The forms of the HAXIS= and VAXIS= options follow. You must precede the first option in a PLOT statement with a slash.
PLOT vertical*horizontal / HAXIS=tick-value-list; |
PLOT vertical*horizontal / VAXIS=tick-value-list; |
For example, to specify tick marks every five years from 1950 to 2000, use the following option:
haxis=1950 1955 1960 1965 1970 1975 1980 1985 1990 1995 2000
Or, you can abbreviate this list of tick marks:
haxis=1950 to 2000 by 5
The following program uses the HAXIS= option to specify the tick mark values for the horizontal axis:
options pagesize=40 linesize=76 pageno=1 nodate; proc plot data=highlow; plot LogDowHigh*Year / haxis=1954 to 1998 by 4; label LogDowHigh='Log of Highest Value' Year='Year Occurred'; title 'Dow Jones Industrial Average Yearly High'; run;
The following output shows the plot:
Specifying the Range and the Intervals of the Horizontal Axis
Dow Jones Industrial Average Yearly High 1 Plot of LogDowHigh*Year. Legend: A = 1 obs, B = 2 obs, etc. | 10.00 + | | | L | o | g | A 9.00 + A o | A f | | A H | i | AA g | A h 8.00 + AA A e | A s | A t | A | V | A a | AA l 7.00 + A A AA u | A AA AA A A A A AA AA e | A A | AA AA A | A | A A | A 6.00 +A -+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+ 1954 1958 1962 1966 1970 1974 1978 1982 1986 1990 1994 1998 Year OccurredThe range of the horizontal axis is from 1954 to 1998, and the tick marks are now arranged at four-year intervals.
Specifying Plotting Symbols |
By default, PROC PLOT uses the letter A as the plotting symbol to indicate one observation, the letter B as the plotting symbol if two observations coincide, the letter C if three coincide, and so on. The letter Z represents 26 or more coinciding observations.
In many instances, particularly if you are plotting two sets of data on the same pair of axes, then you use the following form of the PLOT statement to specify your own plotting symbols:
PLOT vertical*horizontal='character'; |
The following program uses the plus sign (+) as the plotting symbol for the plot:
options pagesize=40 linesize=76 pageno=1 nodate; proc plot data=highlow; plot LogDowHigh*Year='+' / haxis=1954 to 1998 by 4; label LogDowHigh='Log of Highest Value' Year='Year Occurred'; title 'Dow Jones Industrial Average Yearly High'; run;
The plotting symbol must be enclosed in either single or double quotation marks.
The following output shows the plot:
Dow Jones Industrial Average Yearly High 1 Plot of LogDowHigh*Year. Symbol used is '+'. | 10.00 + | | | L | o | g | + 9.00 + + o | + f | | + H | i | ++ g | + h 8.00 + ++ + e | + s | + t | + | V | + a | ++ l 7.00 + + + ++ u | + ++ ++ + + + + ++ ++ e | + + | ++ ++ + | + | + + | + 6.00 ++ -+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+ 1954 1958 1962 1966 1970 1974 1978 1982 1986 1990 1994 1998 Year Occurred
Note: When a plotting symbol is specified, PROC PLOT uses that symbol for all points on the plot regardless of how many observations might coincide. If observations coincide, then a message appears at the bottom of the plot telling how many observations are hidden.
Removing the Legend |
Often, a few simple changes to a plot will improve its appearance. You can draw a frame around the entire plot, rather than just on the left side and bottom. This makes it easier to determine the values that the plotting symbols represent on the left side of the plot. Also, you can suppress the legend when the labels clearly identify the variables in the plot or when the association between the plotting symbols and the variables is clear.
The following program uses the NOLEGEND option in the PROC PLOT statement to suppress the legend and the BOX option in the PLOT statement to box the entire plot:
options pagesize=40 linesize=76 pageno=1 nodate; proc plot data=highlow nolegend; plot LogDowHigh*Year='+' / haxis=1954 to 1998 by 4 box; label LogDowHigh='Log of Highest Value' Year='Year Occurred'; title 'Dow Jones Industrial Average Yearly High'; run;
The following output shows the plot:
Dow Jones Industrial Average Yearly High 1 ---+----+----+----+----+----+----+----+----+----+----+----+--- | | 10.00 + + | | | | | | L | | o | | g | + | 9.00 + + + o | + | f | | | + | H | | i | ++ | g | + | h 8.00 + +++ + e | + | s | + | t | + | | | V | + | a | + + | l 7.00 + ++ ++ + u | ++++ ++ + + ++++ + | e | + + | | + ++++ | | + | | ++ | | + | 6.00 + + + | | ---+----+----+----+----+----+----+----+----+----+----+----+--- 1954 1958 1962 1966 1970 1974 1978 1982 1986 1990 1994 1998 Year Occurred
Copyright © 2012 by SAS Institute Inc., Cary, NC, USA. All rights reserved.