[R] A question regarding Wireframe in Package Lattice

Deepayan Sarkar deepayan.sarkar at gmail.com
Thu Oct 19 20:40:42 CEST 2006


On 10/19/06, Saptarshi Guha <sapsi at pobox.com> wrote:
> Hello,
>         The following code produces a quadrilateral:
>
>                 q<-matrix(c(1,3,1,2,3,1,2,4,2,1,4,2),nrow=4,byrow=T)
>                 qc<-xyz.coords(q)
>                 wireframe(z~y*x,qc)
>         I have 2 questions
>         1) How can i remove the bounding box i.e the cube encompassing the
> quadrilateral?

wireframe(z~y*x, qc, par.settings = list(box.3d = list(col = "transparent"))

Add
scales = list(col = "transparent")
or
scales = list(draw = FALSE)
to remove the arrows/ticks as well.

One warning though: I eventually plan to separate box.3d into two
sets, one for the lines in front, one for the `hidden' ones.
Hopefully, by that time there will be better documentation for
settings.

>         2) Is there any function to get the 2D coordinates of the
> quadrilateral actually used in the final plot   ? I could manually
> calculate the 2D co-ordinates of the projection of the quad if I knew
> the sequnce of 3D transformations 'wireframe' performed upto the
> final step before plotting.

There are two things you need to know:

(1) The range of the bounding box in the "3D space" is not the range
of the data. Usually, it is [-0.5, 0.5]^3, but that can change if
aspect is not c(1, 1). The data are scaled to fit into this box
(actually, xlim, ylim and zlim are scaled to fit into this box). This
is mostly to ensure that the origin is in the middle of the box, which
makes the projection calculations simpler. Inside 'panel.3d.wireframe'
(see ?panel.3dwire), where you should be doing any additional
calculations, these limits are available as the [xyz]lim.scaled
arguments.

(2) Modulo the above, what you want is described in ?utilities.3d.
Extending your example, and making use of the fact that you are using
the defaults for most arguments, we can do:

sq <- scale(q, center = apply(q, 2, function(x) mean(range(x))),
    scale = apply(q, 2, function(x) diff(range(x))))
rot.mat <- ltransform3dMatrix(screen = list(z = 40, x = -60))
ans <- ltransform3dto3d(t(sq), rot.mat, dist = 0.2)
rot.mat
ans

wireframe(z~x*y, qc, par.settings = list(box.3d = list(col = "transparent")),
          scales = list(draw = FALSE),
          xlab = "", ylab = "", zlab = "")
trellis.focus("panel", 1, 1)
panel.points(ans[1, ], ans[2, ])

Note that in the wireframe call I've changed z~y*x to the more natural
z~x*y. Otherwise some reordering of the columns of sq would be
involved.

-Deepayan



More information about the R-help mailing list