SAS.GRAPH 9.1 Reference, Volumes I and II

Requirements: At least one PLOT or SCATTER statement is required.

Global statements: FOOTNOTE, GOPTIONS, TITLE

Reminder: The procedure can include the BY, FORMAT, LABEL, NOTE, and WHERE statements.

Supports: Output Delivery System (ODS)

PROC G3D < DATA= input-data-set >

PROC G3D Statement

Identifies the data set that contains the plot variables . Optionally specifies annotation and an output catalog.

Requirements: An input data set is required.

Syntax

Options

ANNOTATE= Annotate-data-set

ANNO= Annotate-data-set

DATA= input-data-set

GOUT=< libref .> output-catalog

PLOT Statement

Creates three-dimensional surface plots using values of three numeric variables from the input data set.

Requirements: Exactly one plot request is required.

Global statements: FOOTNOTE, TITLE

Description

The PLOT statement specifies one plot request that identifies the three numeric variables to plot. This statement automatically

You can use statement options to modify any of the three plot axes as well as the general appearance of the graph, control the viewing angle, and specify characteristics for reference lines.

In addition, you can use global statements to add text to the graph, and an Annotate data set to enhance the plot.

Syntax

Required Arguments

y*x=z

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

CAXIS= axis-color

CBOTTOM= bottom-surface-color

CTEXT= text-color

CTOP= top-surface-color

DESCRIPTION= entry-description

DES= entry-description

GRID

NAME= entry-name

NOAXIS

NOAXES

NOLABEL

ROTATE= angle-list

SIDE

TILT= angle-list

XTICKNUM= number-of-ticks

YTICKNUM= number-of-ticks

ZTICKNUM= number-of-ticks

XYTYPE=1 2 3

Figure 46.5: Surface Appearance for Different XYTYPE= Values

ZMAX= max-value

ZMIN= min-value

Changing the Surface Appearance

Use the XYTYPE= option to change the appearance of the plot surface. This option lets you select the direction of the lines that form the surface plot. Figure 46.5 on page 1305 shows examples of each type of plot surface.

SCATTER Statement

Creates three-dimensional scatter plots using values of three numeric variables from the input data set.

Requirements: Exactly one plot request is required.

Global statements: FOOTNOTE, TITLE

Alias: SCAT

Description

The SCATTER statement specifies one plot request that identifies the three numeric variables to plot. This statement automatically

You can use statement options to modify any of the three plot axes as well as the general appearance of the graph, control the viewing angle, and specify characteristics for reference lines. In addition, if the needles drawn from the data points to the base plane complicate a graph, you can suppress them.

You can use global statements to add text to the graph, and an Annotate data set to enhance the plot.

Syntax

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

plot-request must be

y*x=z

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

Required Arguments

y*x=z

The SCATTER statement does not require a full grid of observations for the horizontal variable.

Options

Options in a SCATTER 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

CAXIS= axis-color

COLOR= data-point-color data-point-color-variable

CTEXT= text-color

DESCRIPTION= entry-description

DES= entry-description

GRID

NAME= entry-name

NOAXIS

NOAXES

NOLABEL

NONEEDLE

ROTATE= angle-list

SHAPE= symbol-name shape-variable

SIZE= symbol-size size-variable

TILT= angle-list

XTICKNUM= number-of-ticks

YTICKNUM= number-of-ticks

ZTICKNUM= number-of-ticks

ZMAX= max-value

ZMIN= min-value

Changing the Appearance of the Points

Use the COLOR=, SHAPE=, and SIZE= options to change the appearance of your scatter plot or to classify data using color, shape, size, or any combination of these features. Figure 46.6 on page 1309 illustrates the shape names that you can specify in the SHAPE= option. For example, to make all of the data points red balloons at twice the normal size, use

scatter y*x=z /color='red' shape='balloon' size=2;

To size your points according to the values of the variable TYPE in your input data set, use

scatter y*x=z / size=type;

For an example, see Example 5 on page 1320.

Simulating an Overlaid Scatter Plot

You can approximate an overlaid scatter plot by graphing multiple values for the vertical ( z ) variables for a single ( x , y ) position in a single scatter plot. To do this, add a small value to the value of one of the horizontal variables ( x or y ) to give the observation a slightly different ( x , y ) position. Thus, you enable the procedure to plot both values of the vertical ( z ) variable. Represent each different vertical ( z ) variable with a different symbol, size, or color. The resulting plot appears to be multiple plots overlaid on the same axes.

For example, suppose you want to graph a data set that contains two values for the vertical variable Z for each combination of variables X and Y. You could produce the original data set with a DATA step like this:

data planes; input x y z shape $; datalines; 1 1 1 PRISM 1 2 1 PRISM 1 3 1 PRISM 2 1 1 PRISM 2 2 1 PRISM 2 3 1 PRISM 3 1 1 PRISM 3 2 1 PRISM 3 3 1 PRISM 1 1 2 BALLOON 1 2 2 BALLOON 1 3 2 BALLOON 2 1 2 BALLOON 2 2 2 BALLOON 2 3 2 BALLOON 3 1 2 BALLOON 3 2 2 BALLOON 3 3 2 BALLOON ;

The SHAPE variable is assigned a different value for each different Z value for a single combination of X and Y values.

Ordinarily, the SCATTER statement only plots the Z value for the last observation for a single combination of X and Y. However, you can use a DATA step to assign a slightly different x , y position to all observations where Z is greater than 1:

data planes2; set planes; if z > 1 then x = x + .000001; run;

Then you can use a SCATTER statement to produce a plot like the one in Figure 46.7 on page 1312:

proc g3d data=planes2; scatter x*y=z / zmin=0 shape=shape; run; quit;

Figure 46.7: Simulated Overlaid Scatter Plot

Reversing Values on an Axis

Although you can use the SCATTER statement s ROTATE option to alter the view of a plot and therefore the general orientation, you cannot use SCATTER statement options to reverse axis values for one of the plot variables. To do this, you can multiply that variable s values by ˆ’ 1 to reverse the values themselves , which has the result of reversing the axis when those values are used to generate a plot. You should then use PROC FORMAT to define a format that displays the variable s values as they exist in the original data.

For example, the following code generates the scatter plot shown in Figure 46.8 on page 1313:

data original; input y x z; datalines; 1.15 1 .01 1.00 2 .02 1.20 3 .03 1.25 4 .04 1.50 5 .05 2.10 1 .06 2.15 2 .07 2.20 3 .08 2.25 4 .09 2.30 5 .10 ; title1 'Default Y Axis Order'; /* default Y axis order */ proc g3d data=original; scatter y * x = z; run;

Figure 46.8: Default Y-Axis Order

To reverse the Y axis in the plot that is shown in Figure 46.8 on page 1313, you can write a DATA step like the following to reverse the Y values and, therefore, reverse the Y axis when the values are plotted:

data minus_y; set original; y= y; run;

The previous code creates the MINUS_Y data set by reading the ORIGINAL data set, and then multiplying the values of variable Y by -1. Although plotting Y values from the MINUS_Y data set would reverse values on the Y axis, it would misrepresent the original data. Such a plot would label the axis with the negative-Y values. You can correct the problem by using PROC FORMAT to display Y values as they are stored in the ORIGINAL data set:

proc format; picture reverse low < 0 = '09.00' 0 < high = '09.00' (prefix=' ') 0 = '09.00'; run;

Here, the PICTURE statement defines a picture format named REVERSE, which you can refer to in DATA and PROC steps by using the name followed by a period. A picture format is a template for printing numbers . The 09.00 specifications are digit selectors that indicate which digits or columns in the variable values will display in output; columns that do not have a specified digit selector will not be displayed in output. Thus, a picture format for displaying the values of variable Y needs a column for a minus sign, a column for units, and two columns for decimals. The digit selector 0 specifies that no leading zeros will display in a column, and the digit selector 9 specifies that a leading zero will display in a column.

The PICTURE statement defines this new picture format for three data ranges. The lowest value in the data up to but not including zero will display with no prefix, which means negative values will display without a minus sign. All values above (but not including) zero to the highest value in the data will be displayed with the specified prefix, which in this case is a minus sign. Because zero is excluded from both ranges, it is assigned its own picture with no prefix.

You can now assign the REVERSE format to the Y values from the MINUS_Y data set and use Y to generate a scatter plot. The resulting plot displays Y s negative values without a prefix, and its positive values display with a minus sign prefix. This effectively represents Y values as they are stored internally in the ORIGINAL data set, thus correcting the data misrepresentation that results from multiplying Y by ˆ’ 1.

The following code generates the scatter plot shown in Figure 46.9 on page 1314:

title1 'Reverse Y Axis Order'; /* reverses order of default Y axis */ proc g3d data=minus_y; format y reverse.; scatter y*x=z; run; quit;

Figure 46.9: Reverse Y-Axis Order

Категории