spersp
(generic function) draws a perspective plot
of a surface over the x-y
plane with the facets
being filled with different colors and (optionally) adds
a legend strip with the color scale (calls
splot
and persp
).
spersp(x, ...)
"spersp" (x = seq(0, 1, len = nrow(z)), y = seq(0, 1, len = ncol(z)), z, s = z, slim = range(s, finite = TRUE), col = jet.colors(128), breaks = NULL, legend = TRUE, horizontal = FALSE, legend.shrink = 0.8, legend.width = 1.2, legend.mar = ifelse(horizontal, 3.1, 5.1), legend.lab = NULL, bigplot = NULL, smallplot = NULL, lab.breaks = NULL, axis.args = NULL, legend.args = NULL, graphics.reset = FALSE, xlab = NULL, ylab = NULL, zlab = NULL, theta = 40, phi = 20, ticktype = "detailed", cex.axis = 0.75, ...)
"spersp" (x, data.ind = 1, s = x[[data.ind]], xlab = NULL, ylab = NULL, zlab = NULL, ...)
x
coordinate. If x
is a list, its components x$x
and x$y
are
used for x
and y
, respectively. If the list
has component z
this is used for z
.y
coordinate.x
can be used instead of
z
for convenience.TRUE
(default), the
plotting region is splitted into two parts, drawing the
perspective plot in one and the legend with the color
scale in the other. If FALSE
only the (coloured)
perspective plot is drawn and the arguments related to
the legend are ignored (splot
is not
called).z
."simple"
draws just an
arrow parallel to the axis to indicate direction of
increase; "detailed"
draws normal ticks as per 2D
plots.par("cex")
).persp
or spersp.default
; e.g.
xlim, ylim, zlim,
...). NOTE: graphical arguments
passed here will only have impact on the main plot. To
change the graphical defaults for the legend use the
par
function beforehand (e.g.
par(cex.lab = 2)
to increase colorbar labels).z
values to
be plotted.image
for details).col
and be in increasing order.FALSE
(default)
legend will be a vertical strip on the right side. If
TRUE
the legend strip will be along the bottom.image.plot
for details).mtext
function. Usually
this will not be needed (see
image.plot
for details).FALSE
(default)
the plotting region (par("plt")
) will not
be reset to make it possible to add more features to the
plot (e.g. using functions such as points or lines). If
TRUE
will reset plot parameters to the values
before entering the function.x
.y
.persp
for details), a 4 x 4 matrix that can
be used to superimpose additional graphical elements
using the function trans3d
.par(old.par)
will reset plot
parameters to the values before entering the function).par("plt")
) to make it possible to add
more features to the plot (set graphics.reset =
FALSE
to avoid this).splot
, spoints
,
simage
, image
,
image.plot
,
data.grid
, persp
.
#
# Regularly spaced 2D data
nx <- c(40, 40) # ndata = prod(nx)
x1 <- seq(-1, 1, length.out = nx[1])
x2 <- seq(-1, 1, length.out = nx[2])
trend <- outer(x1, x2, function(x,y) x^2 - y^2)
spersp( x1, x2, trend, main = 'Trend', zlab = 'y')
#
# Multiple plots
set.seed(1)
y <- trend + rnorm(prod(nx), 0, 0.1)
x <- as.matrix(expand.grid(x1 = x1, x2 = x2)) # two-dimensional grid
# local polynomial kernel regression
lp <- locpol(x, y, nbin = nx, h = diag(c(0.3, 0.3)))
# 1x2 plot
old.par <- par(mfrow = c(1,2))
spersp( x1, x2, y, main = 'Data')
spersp(lp, main = 'Estimated trend', zlab = 'y')
par(old.par)
Run the code above in your browser using DataLab