R Lattice: How to add y = x line and y = -x lines on the xy plane in the lattice wireframe function?

978 views Asked by At

I'm doing Person-Environment fit research, and hope to add the P = E and P = -E lines on the xy plane of response surface drawn by Lattice wireframe. Currently, I've got the code are as follows:

PersonIV <- seq(-3, 3, length = 30)
EnvironmentIV <- seq(-3, 3, length = 30)
g.test.data <- expand.grid(PersonIV = PersonIV, EnvironmentIV = EnvironmentIV)
g.test.data$DV <- .5 + .4 * PersonIV + .6 * EnvironmentIV + .9 * PersonIV^2 + .7 * PersonIV * EnvironmentIV - .3 * EnvironmentIV^2

library(lattice)
trellis.par.set("axis.line", list(col = NA))
wireframe(DV ~ PersonIV * EnvironmentIV, g.test.data, 
          drape = T, screen = list(z = 30, x = -75), 
          main = "Person - Environment Fit Response Surface", 
          xlab = list(xlim = c(-3:3), label = "Personal IV", col = "black", font = 1, cex = 1, rot = 15), 
          ylab = list(label = "Environment IV", ylim = c(-3: 3), font = 1, cex = 1, rot = -42), 
          zlab = list(label = "DV", zlim = c(0:5), font = 1, cex = 1, rot = 90, lines = T), 
          scale = list(arrows = F, cex = 1, col = "black", tck = 1), 
          par.settings = list(box.3d = list(col=c(1,1,NA,NA,1,NA,1,1,1))), 

          )

Thanks a lot!

1

There are 1 answers

2
Aaron left Stack Overflow On

Making a custom panel function and passing it to the lattice plotting function (here, wireframe) with the panel argument is a common way to do this. To recreate the existing plot, panel.xyplot is usually used, and to add lines, panel.abline is usually used. Perhaps something like this.

panel=function(...) {panel.xyplot(...); panel.abline(0,1); panel.abline(0,-1)}