surface Draw color 3D surface plot with contours in X-Y plane surface

SAS Macro Programs: surface

$Version: 1.0 (26 Oct 2006)
Michael Friendly
York University


The surface macro ( [download] get surface.sas)

Draw color 3D surface plot with contours in X-Y plane

The SURFACE macro draws a 3D color-coded surface plot, showing a contour plot in the X-Y plane. The result is most useful for smooth surfaces, e.g., for functional relations, Z=f(X,Y), bivariate density estimates computed with PROC KDE, or with the result of PROC G3GRID.

Method

The surface and the contour plot are constructed using filled polygons in Annotate datasets. The contour is identical to the surface, with the Z coordinate set to the constant 'floor'.

Usage

The SURFACE macro is defined with keyword parameters. The X=, Y= and Z= parameters are required. The arguments may be listed within parentheses in any order, separated by commas. For example:

  %surface(x=temperature, y=pressure, z=yield);

Parameters

DATA=
The name of the input data set [Default: DATA=_LAST_]
X=
X variable for plot [Default: X=X]
Y=
Y variable for plot [Default: Y=Y]
Z=
Z variable for plot [Default: Z=Z]
WHERE=
Where clause to subset the data
COLORS=
Color scheme (HLS|HLSllss) or list of colors. COLORS=HLS generates NLEVELS= colors varying in hue in the HLS color scheme Hhhh80FF. COLORS=HLSllss, where llss are hex digits, generates HLS colors with lightness ll and saturations ss. Otherwise, COLORS= is taken as a blank separated list of SAS colors of length NLEVELS=. [Default: COLORS=HLS]
NLEVELS=
Number of levels for color [Default: NLEVELS=12]
TICKNUM=
Number of tick marks on axes. Specify 1-3 values, for X, Y and Z. [Default: TICKNUM=5]
DROP=
Amount to drop contour plot beneath lowest z-value, in data units. [Default: DROP=1]
TILT=
G3D TILT value(s): One or more numbers giving the number of degrees to tilt the plot. [Default: TILT=75]
ROTATE=
G3D ROTATE value(s): One or more numbers giving the number of degrees to rotate the plot. [Default: ROTATE=40]
FUZZ=
Fuzz value for binning X, Y [Default: FUZZ=1E-6]
OPTIONS=
REVERSE and/or NOGRID. When COLORS=HLS, OPTIONS=REVERSE reverses the assignment of colors to heights (Z= values) in the plot.
ANNO=
Additional input annotate data set
OUTANNO=
Output annotate data set used with G3D [Default: OUTANNO=SURFANNO]
GOUT=
The name of the graphics catalog [Default: GOUT=GSEG]
NAME=
The name of the graph in the graphic catalog [Default: NAME=SURFACE]

Example

  *-- Generate bivariate normal data;
  data bivar;
    do i = 1 to 10000;
      x = rannor(2140);
      y = -x + 3* rannor(2140);
      output;
    end;
  run;
  *-- Do bivariate density estimation;
  proc kde data=bivar out=kdeout;
    var x y;
  run;
  %include macros(surface);        *-- or include in an autocall library;
  %surface(data=kdeout, x=x, y=y, z=density,
      where=-3 < x < 3)
Plot with reversed Blues palette:
  %brewerpal(n=9, palette=Blues, result=blues9, order=REV);
  %surface(data=kdeout, x=x, y=y, z=density, colors=&blues9, nlevels=9,
      where=-3

See also

brewerpal Generate Brewer color palette(s)
ellipses Plot bivariate data ellipses
mvnormal Generate multivariate normal samples
sunplot Sunflower plot for X-Y data