Unlimited learning, half price | 50% off

Last chance! 50% off unlimited learning

Sale ends in


fields (version 2.3)

drape.plot: Perspective plot draped with colors in the facets.

Description

Function to produce the usual wireframe perspective plot with the facets being filled by according to a colors. By default the colors are assigned from a color bar based on the z values. drape.color is used to create a color matrix different from the z matrix used for the wireframe.

Usage

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")

Arguments

Value

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.

Details

The legend strip may obscure part of the plot. If so add this as another step changing the defaults in image.plot.

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".

See Also

image.plot, persp, plot.surface, surface, lattice, trans3d

Examples

Run this code
# 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