[R] lattice: wireframe "eats up" points; how to make points on wireframe visible?

Marius Hofert m_hofert at web.de
Fri Mar 4 09:17:47 CET 2011


Dear expeRts,

I would like to add two points to a wireframe plot. The points have (x,y,z) coordinates
where z is determined to be on the wireframe [same z-value]. Now something strange
happens. One point is perfectly plotted, the other isn't shown at all. It only 
appears if I move it upwards in z-direction by adding a positive number. So somehow
it disappears in the wireframe-surface *although* the plot symbol [the cross] has 
a positive length in each dimension [I also chose cex=5 to make it large enough so 
that it should (theoretically) be visible]. 

My wireframe plot is a complicated function which I cannot post here. Below is a minimal 
example, however, it didn't show the same problem [the surface is too nice I guess]. 
I therefore *artifically* create the problem in the example below so that you know 
what I mean. For one of the points, I subtract an epsilon [=0.25] in z-direction and 
suddenly the point completely disappears. The strange thing is that the point is 
not even "under" the surface [use the screen-argument to rotate the wireframe plot to check this],
it's simply gone, eaten up by the surface. 

How can I make the two points visible?
I also tried to use the alpha-argument to make the wireframe transparent, but I couldn't 
solve the problem. 

Cheers,

Marius

PS: One also faces this problem for example if one wants to make points visible that are on "opposite sides" of the wireframe.

library(lattice)

f <- function(x) 1/((1-x[1])*(1-x[2])+1)

u <- seq(0, 1, length.out=20)
grid <- expand.grid(x=u, y=u)
x <- grid[,1]
y <- grid[,2]
z <- apply(grid, 1, f)

pt.x <- c(0.2, 0.5)
pt.y <- c(0.6, 0.8)
eps <- 0.25
pts <- rbind(c(pt.x, f(pt.x)-eps), c(pt.y, f(pt.y))) # points to add to the wireframe

wireframe(z~x*y, pts=pts, aspect=1, scales=list(col=1, arrows=FALSE),
          panel.3d.wireframe = function(x,y,z,xlim,ylim,zlim,xlim.scaled,
          ylim.scaled,zlim.scaled,pts,...){
              panel.3dwire(x=x, y=y, z=z, xlim=xlim, ylim=ylim, zlim=zlim,
                           xlim.scaled=xlim.scaled, ylim.scaled=ylim.scaled,
                           zlim.scaled=zlim.scaled, ...)
              panel.3dscatter(x=pts[,1], y=pts[,2], z=pts[,3],
                              xlim=xlim, ylim=ylim, zlim=zlim,
                              xlim.scaled=xlim.scaled, ylim.scaled=ylim.scaled,
                              zlim.scaled=zlim.scaled, type="p", col=c(2,3), 
                              cex=1.8, .scale=TRUE, ...)
          }, key=list(x=0.5, y=0.95, points=list(col=c(2,3)), 
             text=list(c("Point 1", "Point 2")), 
             cex=1, align=TRUE, transparent=TRUE))



More information about the R-help mailing list