|
Using Programming Techniques with PROC GPLOT to Display Multiple Scales and Label Plot Points Illustrated here are two SAS/GRAPH programming techniques: displaying multiple scales on a single set of plot axes using PROC GPLOT, and labeling the plot points without using the ANNOTATE facility. By using the options available on global statements, you can customize your graphics output in a variety of different ways. Suppose you take yearly soil samples and want to produce a plot showing concentrations of nitrogen, potassium, and manganese present in each sample. To differentiate between the elements, you want to label each point with the symbol for the corresponding element. Because nitrogen is found in much higher concentrations than potassium, which in turn is found in much higher levels than manganese, you want the vertical axis segment for each element to show a different range of concentration for each element. First, create a SAS data set containing the variable YEAR, and the variables MN, N, and K, which contain the yearly concentrations of samples of manganese, nitrogen, and potassium, respectively. goptions reset=all ftext=centx htext=3.5 pct; data samples; input year mn n k; cards; 1988 .19 45 10.6 1989 .25 54 9.2 1990 .52 35 11.0 1991 .15 48 7.2 1992 .38 29 8.1 ; Next, create a format to display the data values with percent signs. In the data set, the values represent the actual percentage concentration--that is, a value of .19 represents a concentration of .19 percent, not 19 percent. Rather than using the PERCENTw.d format, which would format a value of .19 to '19%', create a picture format that displays a perrcent sign with the actual values in the data. proc format; picture pctfmt low - high = '009.9%'; run; Then create the AXIS definitions that draw a thick border around the plot area and display multiple scales on the vertical axis. AXIS1 modifies the horizontal axis, using the WIDTH= option to generate a thick axis line. As a result, the border drawn by the CFRAME= option specified in the PLOT statement later in the program is equally thick. The AXIS2 statement defines the left vertical axis. The ORDER= option specifies 3 separate ranges--0 to .6, 6 to 12, and 15 to 60. To provide spacing between the ranges, it adds tick marks between the 3 ranges at intermediate values of 3 and 13. The TICK= option is used to blank out tick mark labels at those values. The AXIS3 statement defines the right vertical axis. It is identical to the AXIS2 definition for the left vertical axis, except that the label for the axis is suppressed.
axis1 offset=(4,4) width=5 value=(h=5 pct) label=none major=none
minor=none order=1988 to 1992 by 1;
axis2 order=(0 to .6 by .2, 3, 6 to 12 by 2, 13, 15 to 60 by 15)
label=(a=90 r=0 'Concentration') value=(tick=5 ' ' tick=10 ' ')
offset=(2,2);
axis3 order=(0 to .6 by .2, 3, 6 to 12 by 2, 13, 15 to 60 by 15)
label=none value=(tick=5 ' ' tick=10 ' ') offset=(2,2);
Next, supply SYMBOL definitions to display and label your data. By default, the SYMBOL1-SYMBOL3 definitions are assigned in order of the variables on the PLOT request. They produce a dark gray dot at each plot point, and connect the points with a line. The SYMBOL4-SYMBOL6 definitions are used with the PLOT2 statement, and display the character symbol of the corresponding element at each plot point. symbol1 interpol=join width=5 color=gray88 value=dot height=6; symbol2 interpol=join width=5 color=gray88 value=dot height=6; symbol3 interpol=join width=5 color=gray88 value=dot height=6; symbol4 interpol=none value='Mn' font=centb color=black height=2; symbol5 interpol=none value='K' font=centb color=black height=2; symbol6 interpol=none value='N' font=centb color=black height=2; Finally, produce the graph with the GPLOT procedure using both a PLOT and a PLOT2 statement. The PLOT statement generates the large joined dots and left vertical axis, and the PLOT2 statement overlays the element symbols and produces the right vertical axis. Both statements use the same plot request. To enhance the axis area, use the CFRAME option to generate a frame with a filled gray background. The VREF= option on the PLOT statement draws reference lines across the plot at the intermediate spacing values to visually separate the three scales on the vertical axis. The FORMAT statement associates the previously-created PCTFMT format with the variables MN, K, and N, and adds a percent sign to the tick labels on the vertical axes. A FOOTNOTE statement is creates a legend.
proc gplot data=samples;
plot (mn k n) * year / overlay vaxis=axis2 haxis=axis1
vref=3, 13 cframe=grayee;
plot2 (mn k n) * year / overlay vaxis=axis3;
format mn k n pctfmt.;
title font=centb color=black height=8 pct 'Sample Analysis';
footnote justify=c font=centb color=black height=3 pct
'N = Nitrogen K = Potassium Mn = Manganese';
run;
quit;
This example provides some ideas for uses of global statements to enhance your SAS/GRAPH output. The variety of options available on AXIS, LEGEND, PATTERN, SYMBOL, TITLE, NOTE and FOOTNOTE statements can be applied in most SAS/GRAPH applications to create more visually appealing and informative graphs. Because some global statements or specific options may not be valid with all graphics procedures, you will want to consult your SAS/GRAPH documentation for correct usage and syntax.
This example was developed by Mike Kalt and Jude Redman. Mike is manager
of the Graphics Support Department and is Advisory Editor of
Observations. Jude is a technical support analyst at the Institute
where she specializes in SAS/GRAPH procedures.
|