Plotting a wireframe AND a cloud with lattice in R

a 夏天 提交于 2019-11-30 07:07:59

I do love rgl! But there are times when 3-D plots in lattice are useful too - you can write your own function which you can pass to the 'panel' argument to lattice functions. For instance,

mypanel <- function(x,y,z,...) {
  panel.wireframe(x,y,z,...)
  panel.cloud(x,y,z,...)
}
wireframe(myGrid$z ~ myGrid$x * myGrid$y, xlab="X", ylab="Y", zlab="Z",
          panel=mypanel)

The last function you call can be wireframe() or cloud(); in either case since panel.wireframe() and panel.cloud() are called within the panel function the result should be the same.

Edit: Thanks for pointing that out, Aaron, then probably you can pass z2 as another variable:

mypanel <- function(x,y,z,z2,...) {
  panel.wireframe(x,y,z,...)
  panel.cloud(x,y,z2,...)
}
wireframe(z ~ x * y, data=myGrid, xlab="X", ylab="Y", zlab="Z",
          panel=mypanel, z2=myGrid$z2)

If memory serves, Rcmdr already does this for you using rgl. That may be limited to the models that Rcmdr fits, though.

On the other hand, it gives you (fast !) scrolling, zooming, ... which lattice cannot do.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!