Arguments

x, y

locations of grid lines at which the values in z are
measured. These must be in ascending order. By default, equally
spaced values from 0 to 1 are used. If x is a list,
its components x$x and x$y are used for x
and y, respectively.

z

a matrix containing the values to be plotted (NAs are
allowed). Note that x can be used instead of z for
convenience.

xlim, ylim, zlim

x-, y- and z-limits. These should be chosen
to cover the range of values of the surface: see ‘Details’.

xlab, ylab, zlab

titles for the axes. N.B. These must be
character strings; expressions are not accepted. Numbers will be
coerced to character strings.

a value which can be used to vary the strength of
the perspective transformation. Values of d greater
than 1 will lessen the perspective effect and values less
and 1 will exaggerate it.

scale

before viewing the x, y and z coordinates of the
points defining the surface are transformed to the interval
[0,1]. If scale is TRUE the x, y and z coordinates
are transformed separately. If scale is FALSE
the coordinates are scaled so that aspect ratios are retained.
This is useful for rendering things like DEM information.

expand

a expansion factor applied to the z
coordinates. Often used with 0 < expand < 1 to shrink the
plotting box in the z direction.

col

the color(s) of the surface facets. Transparent colours are
ignored. This is recycled to the \((nx-1)(ny-1)\) facets.

border

the color of the line drawn around the surface facets.
The default, NULL, corresponds to par("fg").
A value of NA will disable the drawing of borders: this is
sometimes useful when the surface is shaded.

ltheta, lphi

if finite values are specified for ltheta
and lphi, the surface is shaded as though it was being
illuminated from the direction specified by azimuth ltheta
and colatitude lphi.

shade

the shade at a surface facet is computed as
((1+d)/2)^shade, where d is the dot product of
a unit vector normal to the facet and a unit vector in the
direction of a light source. Values of shade close
to one yield shading similar to a point light source model
and values close to zero produce no shading. Values in the
range 0.5 to 0.75 provide an approximation to daylight
illumination.

box

should the bounding box for the surface be displayed.
The default is TRUE.

axes

should ticks and labels be added to the box. The
default is TRUE. If box is FALSE then no
ticks or labels are drawn.

ticktype

character: "simple" draws just an arrow
parallel to the axis to indicate direction of increase;
"detailed" draws normal ticks as per 2D plots.

nticks

the (approximate) number of tick marks to draw on the
axes. Has no effect if ticktype is "simple".

Details

The plots are produced by first transforming the (x,y,z)
coordinates to the interval [0,1] using the limits supplied or
computed from the range of the data. The surface is then viewed
by looking at the origin from a direction defined by theta
and phi. If theta and phi are both zero
the viewing direction is directly down the negative y axis.
Changing theta will vary the azimuth and changing phi
the colatitude.

There is a hook called "persp" (see setHook)
called after the plot is completed, which is used in the
testing code to annotate the plot page. The hook function(s) are
called with no argument.

Notice that persp interprets the z matrix as a table of
f(x[i], y[j]) values, so that the x axis corresponds to row
number and the y axis to column number, with column 1 at the bottom,
so that with the standard rotation angles, the top left corner of the
matrix is displayed at the left hand side, closest to the user.

The sizes and fonts of the axis labels and the annotations for
ticktype = "detailed" are controlled by graphics parameters
"cex.lab"/"font.lab" and
"cex.axis"/"font.axis" respectively.

The bounding box is drawn with edges of faces facing away from the
viewer (and hence at the back of the box) with solid lines and other
edges dashed and on top of the surface. This (and the plotting of the
axes) assumes that the axis limits are chosen so that the surface
is within the box, and the function will warn if this is not the case.

Value

persp() returns the viewing transformation matrix, say
VT, a \(4 \times 4\) matrix suitable for projecting 3D
coordinates \((x,y,z)\) into the 2D plane using homogeneous 4D
coordinates \((x,y,z,t)\). It can be used to superimpose
additional graphical elements on the 3D plot, by
lines() or points(), using the
function trans3d().