Camarda, Carlo Giovanni
2009-Mar-19 18:27 UTC
[R] two plots side-by-side with persp3d(rgl)
Dear R-users, I would like to place two 3D plots side-by-side in a rgl-setting. It would nice to have something like "par(mfrow=c(1,2))" for basic plots, or an array framework for wireframe(lattice) (see example below). I only managed to overlap two persp3d plots. My final idea would be to animate both surfaces using play3d(rgl). Thanks in advance for any help. Best, Carlo Giovanni Camarda # simple datasets x <- seq(-10, 10, length= 30) y <- x f <- function(x,y) { r <- sqrt(x^2+y^2); 10 * sin(r)/r } z1 <- outer(x, y, f) z1[is.na(z1)] <- 1 z2 <- matrix(outer(1:30, 1:30)/200, 30, 30) # simple persp par(mfrow=c(1,2)) persp(x, y, z1) persp(x, y, z2) # wireframe library(lattice) grid. <- expand.grid(list(x=x,y=y,name=c("Z1", "Z2"))) grid.$Z <- c(c(z1), c(z2)) wireframe(Z ~ x * y | name, data = grid.) # single plot library(rgl) persp3d(x, y, z1) persp3d(x, y, z2) # overlapping plots persp3d(x,y,z1, color="#CCCCFF", front="lines") persp3d(x,y,z2, col="red", add=TRUE) play3d(spin3d(axis=c(0,0,1), rpm=10), duration=5) ----------------------------------------------------- Dr. Carlo Giovanni Camarda Research Scientist Max Planck Institute for Demographic Research Laboratory of Statistical Demography Konrad-Zuse-Straße 1 18057 Rostock - Germany Phone: +49 (0)381 2081 172 Fax: +49 (0)381 2081 472 camarda@demogr.mpg.de http://www.demogr.mpg.de/en/staff/camarda/default.htm ----------------------------------------------------- ---------- This mail has been sent through the MPI for Demographic ...{{dropped:10}}
On 3/19/2009 2:27 PM, Camarda, Carlo Giovanni wrote:> Dear R-users, > > I would like to place two 3D plots side-by-side in a rgl-setting. It would nice to have something like "par(mfrow=c(1,2))" for basic plots, or an array framework for wireframe(lattice) (see example below). I only managed to overlap two persp3d plots. > My final idea would be to animate both surfaces using play3d(rgl).This is not easy; it's something that's been on my todo list for a long time. Currently the closest you can do is to open two windows and place them side by side (code can do that). Then you can control both together. Example code is in demo(mouseCallbacks) and demo(stereo). Duncan Murdoch> > Thanks in advance for any help. > > Best, > Carlo Giovanni Camarda > > > # simple datasets > x <- seq(-10, 10, length= 30) > y <- x > f <- function(x,y) { r <- sqrt(x^2+y^2); 10 * sin(r)/r } > z1 <- outer(x, y, f) > z1[is.na(z1)] <- 1 > z2 <- matrix(outer(1:30, 1:30)/200, 30, 30) > > # simple persp > par(mfrow=c(1,2)) > persp(x, y, z1) > persp(x, y, z2) > > # wireframe > library(lattice) > grid. <- expand.grid(list(x=x,y=y,name=c("Z1", "Z2"))) > grid.$Z <- c(c(z1), c(z2)) > wireframe(Z ~ x * y | name, data = grid.) > > # single plot > library(rgl) > persp3d(x, y, z1) > persp3d(x, y, z2) > > # overlapping plots > persp3d(x,y,z1, color="#CCCCFF", front="lines") > persp3d(x,y,z2, col="red", add=TRUE) > play3d(spin3d(axis=c(0,0,1), rpm=10), duration=5) > > > > ----------------------------------------------------- > Dr. Carlo Giovanni Camarda > Research Scientist > Max Planck Institute for Demographic Research > Laboratory of Statistical Demography > Konrad-Zuse-Stra? 1 > 18057 Rostock - Germany > Phone: +49 (0)381 2081 172 > Fax: +49 (0)381 2081 472 > camarda at demogr.mpg.de > http://www.demogr.mpg.de/en/staff/camarda/default.htm > ----------------------------------------------------- > > > > > > ---------- > This mail has been sent through the MPI for Demographic ...{{dropped:10}} > > > > ------------------------------------------------------------------------ > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.