[R] plotting two surfaces simultaneously in a single panel

Deepayan Sarkar deepayan.sarkar at gmail.com
Wed Dec 2 15:46:54 CET 2009


On Fri, Nov 27, 2009 at 6:14 PM, Umesh Srinivasan
<umesh.srinivasan at gmail.com> wrote:
> Hi,
>
> I have recently begun using the lattice package, and have been using
> the wireframe command to visualise matrices which are model outputs. I
> have been trying to plot two surfaces (from two matrices)
> simultaneously in one panel, to visualise intersections etc., but
> neither my attempts or trawling the net are helping me find how to do
> this.

The documentation for wireframe mentions the use of 'groups' to do
this, and the usual shortcut of using formulae of the form z1+z2 ~ x +
y also works. The following seems to work as expected, subject to
caveats mentioned in ?wireframe and ?panel.wireframe (there is no
hidden surface removal going on, so intersections will not be shown
correctly).

df <- as.data.frame.table(volcano)
names(df) <- c("x", "y", "height")
df$sheight <- scale(df$height)

wireframe(sheight + (-sheight) ~ x + y, df, aspect = c(1, .5))

-Deepayan




More information about the R-help mailing list