[R] Lattice: use levelplot as panel for wireframe

Deepayan Sarkar deepayan.sarkar at gmail.com
Thu May 7 01:27:33 CEST 2009


On Tue, May 5, 2009 at 4:07 AM, Anton Bossenbroek
<anton.bossenbroek at me.com> wrote:
> Hi,
>
> I want to draw a figure similar to
> http://dsarkar.fhcrc.org/lattice/book/images/Figure_13_07_stdBW.png from
> http://lmdvr.r-forge.r-project.org/figures/figures.html (figure 13.7) .
> However instead of using a contour plot as a panel for the wireframe I want
> to use a levelplot. Can somebody help me with this?

It's difficult to use the same idea, as rectangles (defined by center
and width/height) become more complicated polygons in 3-D.

A simple approximation is to plot a second surface with drape=TRUE
(which produces a levelplot-like color scheme), making the vertical
span of the surface small enough to make it look flat. For example,

panel.3d.levelplot <-
    function(x, y, z, rot.mat, distance, zlim.scaled, at,
             drape = TRUE, shade = FALSE, ...)
{
    panel.3dwire(x, y, z, rot.mat = rot.mat, distance = distance,
                zlim.scaled = zlim.scaled, at = at,
                drape = FALSE, shade = shade, ...)
    zrng <- 0.001 * diff(zlim.scaled) ## vertical range of 2nd surface (>0)
    z.scaled <- (z - min(z))/diff(range(z))
    at.scaled <- (at - min(z))/diff(range(z))
    new.z <- zlim.scaled[2] + zrng * (z.scaled-1)
    new.at <- zlim.scaled[2] + zrng * (at.scaled-1)
    panel.3dwire(x, y, new.z, at = new.at,
                 col = "transparent",
                 rot.mat = rot.mat, distance = distance,
                 shade = FALSE,
                 drape = TRUE,
                 zlim.scaled = zlim.scaled,
                 alpha = 0.8,
                 ...)
}

wireframe(volcano, zlim = c(90, 250), nlevels = 10,
          aspect = c(61/87, .3), panel.aspect = 0.6,
          panel.3d.wireframe = panel.3d.levelplot,
          at = pretty(volcano, 10),
          shade = TRUE,
          col.regions = terrain.colors(100),
          screen = list(z = 20, x = -60))


-Deepayan




More information about the R-help mailing list