Procedure features:
PLOT statement
Sample library member: GTDSURFA
This example shows a surface plot that reveals the shape of a generated data set named HAT. The PLOT statement in this example relies entirely on procedure defaults. The axes are scaled to include all data values and are labeled with the names of the axes variables . The axes major tick marks are divided into three even intervals, and the horizontal plane is rotated 70 ° around the z axis and tilted 70 ° toward you. The plot is displayed with the colors that the GOPTIONS statement defines for the colors list.
Assign the libref and set the graphics environment.
libname reflib ' SAS-data-library '; goptions reset=global gunit=pct border cback=white colors=(black blue green red) ftext=swiss ftitle=swissb htitle=6 htext=4;
Create the data set. REFLIB.HAT is generated data that produces a symmetric surface pattern, which is useful for illustrating the PLOT statement and its options.
data reflib.hat; do x= 5 to 5 by 0.25; do y= 5 to 5 by 0.25; z=sin(sqrt(x*x+y*y)); output; end; end; run;
Define title and footnote.
title 'Surface Plot of HAT Data Set'; footnote j=r 'GTDSURFA';
Generate the surface plot.
proc g3d data=reflib.hat; plot y*x=z; run; quit;
Procedure Features
PLOT statement options:
CBOTTOM=
CTOP=
GRID
ROTATE=
YTICKNUM=
ZMAX=
ZMIN=
ZTICKNUM=
Data set: REFLIB.HAT on page 1315
Sample library member: GTDROTAT
This example rotates the surface plot that is shown in Example 4 on page 1318 and enhances its axes by adding reference lines and increasing the number of tick marks on the y and z axes. It also raises the plot above the horizontal x-y plane.
Assign the libref and set the graphics environment.
libname reflib ' SAS-data-library '; goptions reset=global gunit=pct border cback=white colors=(black blue green red) ftext=swiss ftitle=swissb htitle=6 htext=4;
Define title and footnote.
title 'Surface Plot of HAT Data Set'; footnote j=r 'GTDROTAT';
Generate the surface plot. GRID draws reference lines for all x, y, and z axis tick marks. ROTATE= specifies a rotation angle of 45 °. CTOP= and CBOTTOM= change the colors of the plot s top and bottom surfaces. YTICKNUM= and ZTICKNUM= specify the number of tick marks for the y and z axes. ZMIN= and ZMAX= specify minimum and maximum values for the z axis. Data that exceeds the range of ZMIN-to-ZMAX is displayed at the value of ZMIN or ZMAX. Specifying a ZMIN= value that is below the minimum value in the data effectively raises the plot above the horizontal plane.
proc g3d data=reflib.hat; plot y*x=z / grid rotate=45 ctop=red cbottom=black yticknum=5 zticknum=5 zmin= 3 zmax=1; run; quit;
Procedure features:
PLOT statement options:
SIDE
TILT=
Data set: REFLIB.HAT on page 1315
Sample library member: GTDTILT
This example modifies that shown in Example 1 on page 1314 by tilting the surface plot 15 toward you and adding a side wall.
Assign the libref and set the graphics environment.
goptions reset=global gunit=pct border cback=white colors=(black blue green red) ftext=swiss ftitle=swissb htitle=6 htext=4;
Define title and footnote.
title 'Surface Plot of HAT Data Set'; footnote j=r 'GTDTILT';
Generate the surface plot. SIDE draws a side wall for the graph. TILT= specifies a tilt angle of 15 ° for the plot, which doesn t affect the default rotation of 70 °.
proc g3d data=work.hat; plot y*x=z / side tilt=15; run; quit;
Procedure features:
SCATTER statement
Sample library member: GTDSCATR
This example shows a scatter plot that examines the results of measuring the petal length, petal width, and sepal length for the flowers of three species of iris. The SCATTER statement in this example relies entirely on procedure defaults, which scale the axes to include all data values, label the axes with the names of the axes variables, divide the axes into three even intervals, rotate the horizontal plane 70 ° around the z axis and tilt it 70 ° toward you, and display the plot with the colors that are defined for the colors list. The data points are represented by pyramids , which are connected to the horizontal plane with needles .
Assign the libref and set the graphics environment.
libname reflib ' SAS-data-library '; goptions reset=global gunit=pct border cback=white colors=(black blue green red) ftext=swiss ftitle=swissb htitle=6 htext=4;
Create data set. REFLIB.IRIS contains petal and sepal measurements for the flowers of three iris species, which are identified by species numbers .
data reflib.iris; input sepallen sepalwid petallen petalwid spec_no; datalines; 50 33 14 02 1 64 28 56 22 3 ... more data lines ... 63 33 60 25 3 53 37 15 02 1 ;
Define titles and footnotes.
title1 'Iris Species Classification'; title2 'Physical Measurement'; title3 'Source: Fisher (1936) Iris Data'; footnote1 j=l ' Petallen: Petal Length in mm.' j=r 'Sepallen: Sepal Length in mm. '; footnote2 j=l ' Petalwid: Petal Width in mm.' j=r 'Sepal Width not shown '; footnote3 j=r 'GTDSCATR';
Generate a simple scatter plot.
proc g3d data=reflib.iris; scatter petallen*petalwid=sepallen; run; quit;
Procedure features:
SCATTER statement options:
COLOR =
GRID
NONEEDLE
SHAPE=
Other features:
DATA step
LABEL statement
NOTE statement
Data set: REFLIB.IRIS (see Example 4 on page 1318)
Sample library member: GTDSHAPE
This program modifies that shown in Example 4 on page 1318 to use shape symbols and color to distinguish information for various iris species. It also uses NOTE statements to simulate a plot legend.
The program then generates a second plot to modify the first. As shown by the following output, the second plot request suppresses the needles that connect data points to the horizontal plane, and adds reference lines to make it easier to interpret data values. It also labels the plot axes with descriptive text.
Assign the libref and set the graphics environment.
libname reflib ' SAS-data-library '; goptions reset=global gunit=pct border cback=white colors=(black blue green red) ftext=swiss ftitle=swissb htitle=6 htext=4;
Create data set. REFLIB.IRIS2 uses a DATA step to read and modify the REFLIB.IRIS data set. The DATA step adds a variable that identifies the iris species. It also adds two additional variables that store shape and color values for each iris species. These shapes and colors will distinguish iris species in the plot.
data reflib.iris2; set reflib.iris; length species . colorval . shapeval .; if spec_no=1 then do; species='setosa'; shapeval='club'; colorval='blue'; end; if spec_no=2 then do; species='versicolor'; shapeval='diamond'; colorval='red'; end; if spec_no=3 then do; species='virginica'; shapeval='spade'; colorval='green'; end; run;
Define titles and footnotes.
title1 'Iris Species Classification'; title2 'Physical Measurement'; title3 'Source: Fisher (1936) Iris Data'; footnote1 j=l ' Petallen: Petal Length in mm.' j=r 'Petalwid: Petal Width in mm. '; footnote2 j=l ' Sepallen: Sepal Length in mm.' j=r 'Sepal Width not shown '; footnote3 j=r 'GTDSHAPE(a)';
Generate the plot. COLOR= specifies the variable that contains color information for the iris species. SHAPE= specifies the variable that contains shape information for the iris species.
proc g3d data=reflib.iris2; scatter petallen*petalwid=sepallen / color=colorval shape=shapeval;
Create a legend using NOTE statements. The first NOTE statement clears any existing notes. The second NOTE statement identifies the color key used for the different iris species.
note; note j=r 'Species: ' c=green 'Virginica ' j=r c=red 'Versicolor ' j=r c=blue 'Setosa '; run;
Define new title and footnotes.
title3; footnote1 j=l ' Source: Fisher (1936) Iris Data'; footnote2 j=r 'GTDSHAPE(b)';
Generate the plot. NONEEDLE suppresses the line drawn from the x-y plane to the plot point. GRID draws reference lines for x, y, and z axis tick marks.
proc g3d data=reflib.iris2; scatter petallen*petalwid=sepallen / noneedle grid color=colorval shape=shapeval;
Change the axes labels. To improve axes labels, the LABEL statement associates labels with variable names.
label petallen='Petal Length' petalwid='Petal Width' sepallen='Sepal Length'; run; quit;
Procedure features:
SCATTER statement options
CAXIS=
ROTATE=
SIZE =
XTICKNUM
YTICKNUM=
ZMAX=
ZMIN=
ZTICKNUM=
Other features: DATA step
Sample library member: GTDROTSC
This example produces a scatter plot of humidity data. It uses color to distinguish air temperature ranges. The plot is rotated ˆ’ 15 ° .
Assign the libref and set the graphics environment.
libname reflib ' SAS-data-library '; goptions reset=global gunit=pct border cback=white colors=(black blue green red) ftext=swiss ftitle=swissb htitle=6 htext=4;
Create data set REFLIB.HUMID. The DATA step varies color according to specified air-temperature ranges.
data reflib.humid; length colorval $ 8.; label wtemp='Wet-Bulb Temp'; label relhum='Rel. Humidity'; label atemp=' Air Temp.'; input atemp wtemp relhum; if atemp<26 then colorval="blue"; else if atemp>=26 and atemp<+52 then colorval="red"; else if atemp>=52 and atemp<+78 then colorval="green"; else if atemp>=78 and atemp<+104 then colorval="lib"; else if atemp>104 then colorval="pink "; datalines; 0 1 67 0 2 33 ... more data lines ... 130 34 29 130 35 28 ;
Define title and footnotes.
title 'Relative Humidity in Percent'; footnote1 j=l ' Source: William L. Donn, Meteorology, Fourth Edition'; footnote2 j=r 'GTDROTSC';
Generate the plot. CAXIS= specifies a color for the axis lines and tick marks. ROTATE= specifies a rotation angle for the plot. SIZE= specifies the size of the plot symbols. XTICKNUM=, YTICKNUM=, and ZTICKNUM= specify the number of tick marks for the x, y, and z axes. ZMIN= and ZMAX= specify the minimum and maximum values for the z axis. Z-axis values that exceed the values of the ZMAX= and ZMIN= options will be displayed at the value of ZMAX= or ZMIN=.
proc g3d data=reflib.humid; scatter atemp*wtemp=relhum / shape='pillar' color=colorval caxis=blue rotate=-15 size=.5 yticknum=5 xticknum=2 zticknum=4 zmin=0 zmax=100; run; quit;