
Last chance! 50% off unlimited learning
Sale ends in
drape.color
is used to create
a color matrix different from the z matrix used for the wireframe.drape.plot( x,y,z,z2=NULL, col = tim.colors(64), zlim = NULL,
add.legend = TRUE, horizontal = TRUE, theta = 30, phi = 20, ...)drape.color(z, col = tim.colors(64), zlim = NULL,
transperent.color = "white")
drape.plot
If an assignment is made the projection matrix from persp is returned.
This information can be used to add additional 3-d features to the plot.
See the persp
help file for an example how to add additional points
and lines using the trans3d
function and also the example below.
drape.color
If dim( z) = M,N this function returns an (M-1)X(N-1)
matrix where each element is a text string specifying the color.
When using drape.color just drop the results into the col
argument
of persp
. Having said written this, no surprises what drape.plot
does it calls drape.color
followed by persp
and finally
the legend strip is added with image.plot
.
The color assignments are done by dividing up the zlim interval into equally spaced bins, adding a very small inflation to the z limits. The mean z values, comprising an (M-1)X(N-1) matrix, for each facet are discretized to the bins. The bin numbers then become the indices used for the color scale. If zlim is not specified it is the range of the z or z2 matrix is used to generate the ranges of the color bar. Note that this may be different than the range of the mean facets.
This kind of plot is also supported through the wireframed function in the lattice package. The advantage of this fields version is that it uses the standard R graphics functions -- and is written in R code.
The drape plot is also drawn by the fields surface
function with
type="P"
.
# an obvious choice:
# Mr. R's favorite New Zealand Volcano!
data( volcano)
M<- nrow( volcano)
N<- ncol( volcano)
x<- seq( 0,1,,M)
y<- seq( 0,1,,N)
drape.plot( x,y,volcano, col=terrain.colors(128))-> pm
#note the projection has been saved in pm
# add a point marking the summit
max( volcano)-> zsummit
ix<- row( volcano)[volcano==zsummit]
iy<- col( volcano)[volcano==zsummit]
trans3d( x[ix], y[iy],zsummit,pm)-> uv
points( uv, col="magenta", pch="+", cex=2)
# overlay volcano wireframe with gradient in x direction.
dz<- (
volcano[1:(M-1), 1:(N-1)] - volcano[2:(M), 1:(N-1)] +
volcano[1:(M-1), 2:(N)] - volcano[2:(M), 2:(N)]
)/2
# convert dz to a color scale:
zlim<- range( c( dz), na.rm=TRUE)
drape.color( dz, zlim =zlim)-> zcol
# wireframe with these colors
persp( volcano, col=zcol, theta=30, phi=20)
# add legend using image.plot function
image.plot( zlim=zlim, legend.only =TRUE, horizontal =TRUE)
Run the code above in your browser using DataLab