persp {base} | R Documentation |
This function draws perspective plots of surfaces over the
x–y plane. persp
is a generic function.
persp(x, ...)
persp.default(x = seq(0, 1, len = nrow(z)), y = seq(0, 1, len = ncol(z)), z,
xlim = range(x), ylim = range(y), zlim = range(z, na.rm = TRUE),
xlab = NULL, ylab = NULL, zlab = NULL, main = NULL, sub = NULL,
theta = 0, phi = 15, r = sqrt(3), d = 1, scale = TRUE, expand = 1,
col = "white", border = NULL, ltheta = -135, lphi = 0, shade = NA,
box = TRUE, axes = TRUE, nticks = 5, ticktype = "simple",
...)
x , y |
locations of grid lines at which the values in |
z |
a matrix containing the values to be plotted ( |
xlim , ylim , zlim |
x-, y- and z-limits. The plot is produced so that the rectangular volume defined by these limits is visible. |
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. |
main , sub |
main and sub title, as for |
theta , phi |
angles defining the viewing direction.
|
r |
the distance of the eyepoint from the centre of the plotting box. |
d |
a value which can be used to vary the strength of
the perspective transformation. Values of |
scale |
before viewing the x, y and z coordinates of the
points defining the surface are transformed to the interval
[0,1]. If |
expand |
a expansion factor applied to the |
col |
the color of the surface facets. Transparent colours are ignored. |
border |
the color of the line drawn around the surface facets.
A value of |
ltheta , lphi |
if finite values are specified for |
shade |
the shade at a surface facet is computed as
|
box |
should the bounding box for the surface be displayed.
The default is |
axes |
should ticks and labels be added to the box. The
default is |
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 |
... |
additional graphical parameters (see |
The plots are produced by first transforming the
coordinates to the interval [0,1]. 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.
contour
and image
.
# (1) The Obligatory Mathematical surface.
# Rotated sinc function.
x <- seq(-10, 10, length=50)
y <- x
f <- function(x,y)
{
r <- sqrt(x^2+y^2)
10 * sin(r)/r
}
z <- outer(x, y, f)
z[is.na(z)] <- 1
par(bg = "white")
persp(x, y, z, theta = 30, phi = 30, expand = 0.5, col = "lightblue",
xlab = "X", ylab = "Y", zlab = "Z")
persp(x, y, z, theta = 30, phi = 30, expand = 0.5, col = "lightblue",
ltheta = 120, shade = 0.75, ticktype = "detailed",
xlab = "X", ylab = "Y", zlab = "Z")
# (2) Visualizing a simple DEM model
data(volcano)
z <- 2 * volcano # Exaggerate the relief
x <- 10 * (1:nrow(z)) # 10 meter spacing (S to N)
y <- 10 * (1:ncol(z)) # 10 meter spacing (E to W)
persp(x, y, z, theta = 120, phi = 15, scale = FALSE, axes = FALSE)
# (3) Now something more complex
# We border the surface, to make it more "slice like"
# and color the top and sides of the surface differently.
zmin <- min(z) - 20
z <- rbind(zmin, cbind(zmin, z, zmin), zmin)
x <- c(min(x) - 1e-10, x, max(x) + 1e-10)
y <- c(min(y) - 1e-10, y, max(y) + 1e-10)
fill <- matrix("green3", nr = nrow(z)-1, nc = ncol(z)-1)
fill[,1] <- "gray"
fill[,ncol(fill)] <- "gray"
fill[1,] <- "gray"
fill[nrow(fill),] <- "gray"
par(bg = "lightblue")
persp(x, y, z, theta = 120, phi = 15, col = fill, scale = FALSE, axes = FALSE)
title(main = "Maunga Whau\nOne of 50 Volcanoes in the Auckland Region.",
font.main = 4)
par(bg = "slategray")
persp(x, y, z, theta = 135, phi = 30, col = fill, scale = FALSE,
ltheta = -120, lphi = 15, shade = 0.65, axes = FALSE)
persp(x, y, z, theta = 135, phi = 30, col = "green3", scale = FALSE,
ltheta = -120, shade = 0.75, border = NA, box = FALSE)