contour3D
adds a contour in a 3D plot.
1 2 3 4 5 
x, y, z 
Matrix (2D), vector, or one value containing the values where the image is to be plotted. At least one of them should be one number, as this will determine where the image is plotted, parallel to the (yz) plane (x one number), to the (xz) plane (y one number) or to the (zy) plane (z one number). If two are vectors, the first vector should be of length equal to

colvar 
The variable used for coloring.
Values of 
col 
Color palette to be used for the 
colkey 
A logical, The default is to draw the color key on side = 4, i.e. in the right margin.
If 
clab 
Only if 
clim 
Only if 
theta, phi 
The angles defining the viewing direction.

panel.first 
A 
bty 
The type of the box, the default only drawing background panels.
Only effective if the persp
argument ( 
dDepth 
When a contour is added on an image, the image polygons may
hide some contour segments. To avoid that, the viewing depth of the segments
can be artificially decreased with the factor 
addbox 
If 
add 
Logical. If 
plot 
Logical. If 
... 
additional arguments passed to the plotting methods. The following persp arguments can be specified:
In addition, the perspbox arguments
The arguments
The arguments after ... must be matched exactly. 
Returns the viewing transformation matrix. See trans3D.
Karline Soetaert <karline.soetaert@nioz.nl>
contour for R's 2D contour function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53  # save plotting parameters
pm < par("mfrow")
## =======================================================================
## Contours
## =======================================================================
par (mfrow = c(2, 2))
r < 1:nrow(volcano)
c < 1:ncol(volcano)
contour3D(x = r, y = c, z = 100, colvar = volcano, zlim = c(0, 150),
clab = c("height", "m"))
contour3D(x = 100, y = r, z = c, colvar = volcano, clab = c("height", "m"))
contour3D(z = volcano, colvar = volcano, lwd = 2,
nlevels = 20, clab = c("height", "m"), colkey = FALSE)
contour3D(y = volcano, colvar = volcano, lwd = 2,
nlevels = 10, clab = c("height", "m"))
## =======================================================================
## Composite images and contours in 3D
## =======================================================================
persp3D(z = volcano, zlim = c(90, 300), col = "white",
shade = 0.1, d = 2, plot = FALSE)
contour3D(z = volcano, colvar = volcano, lwd = 2, add = TRUE,
nlevels = 20, clab = c("height", "m"), plot = FALSE,
colkey = list(at = seq(90, 190, length.out = 5)))
contour3D(z = 300, colvar = volcano, lwd = 2, col = "grey",
add = TRUE, nlevels = 5)
## =======================================================================
## the viewing depth of contours (dDepth)
## =======================================================================
# too low
persp3D(z = volcano, col = "white", shade = 0.1, plot = FALSE)
contour3D(z = volcano, colvar = volcano, lwd = 2,
add = TRUE, dDepth = 0, col = "black")
# default
persp3D(z = volcano, col = "white", shade = 0.1, plot = FALSE)
contour3D(z = volcano, colvar = volcano, lwd = 2,
add = TRUE, dDepth = 0.1, col = "black")
# too high
persp3D(z = volcano, col = "white", shade = 0.1, plot = FALSE)
contour3D(z = volcano, colvar = volcano, lwd = 1,
add = TRUE, dDepth = 0.5, col = "black")
# reset plotting parameters
par(mfrow = pm)

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.
All documentation is copyright its authors; we didn't write any of that.