Dear all, I would like to put two perspective plots into one plot. The help page for ?persp shows how one can add points and lines but not another perspective plot. data(volcano) z <- 2 * volcano # Exaggerate the relief x <- 10 * (1:nrow(z)) # 10 meter spacing (S to N) y <- 10 * (1:ncol(z)) # 10 meter spacing (E to W) ## Don't draw the grid lines : border = NA persp(x, y, z, theta = 135, phi = 30, col = "green3", scale = FALSE, ltheta = -120, shade = 0.75, border = NA, box = FALSE) and now I would like to include another surface. I was hoping for a possibility like add=TRUE such as in contour: persp(x, y, z+10, theta = 135, phi = 30, col = "red", add=TRUE) Can someone point out to me how it can be accomplished (maybe a function in another package)? Thank you very much, Roland [[alternative HTML version deleted]]
Probably the easiest way is to use the "wireframe" function in the lattice package. The second example in the help shows 2 surfaces (you do need to combine the data into a single data frame). If you really want to use the "persp" function, then you could create the first plot, then call "par(new=TRUE)" and then do the 2nd plot, but that would take a lot of thinking to get the axes and scales to line up properly and make it look good. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at intermountainmail.org (801) 408-8111> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Roland Rau > Sent: Friday, February 09, 2007 9:01 AM > To: r-help > Subject: [R] two perspective plots in in plot > > Dear all, > > I would like to put two perspective plots into one plot. The > help page for ?persp shows how one can add points and lines > but not another perspective plot. > > data(volcano) > z <- 2 * volcano # Exaggerate the relief > x <- 10 * (1:nrow(z)) # 10 meter spacing (S to N) > y <- 10 * (1:ncol(z)) # 10 meter spacing (E to W) > ## Don't draw the grid lines : border = NA persp(x, y, z, > theta = 135, phi = 30, col = "green3", scale = FALSE, > ltheta = -120, shade = 0.75, border = NA, box = FALSE) > > and now I would like to include another surface. I was hoping > for a possibility like add=TRUE such as in contour: > > persp(x, y, z+10, theta = 135, phi = 30, col = "red", add=TRUE) > > Can someone point out to me how it can be accomplished (maybe > a function in another package)? > > Thank you very much, > Roland > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >
On 2/9/2007 1:11 PM, Greg Snow wrote:> Probably the easiest way is to use the "wireframe" function in the > lattice package. The second example in the help shows 2 surfaces (you > do need to combine the data into a single data frame). > > If you really want to use the "persp" function, then you could create > the first plot, then call "par(new=TRUE)" and then do the 2nd plot, but > that would take a lot of thinking to get the axes and scales to line up > properly and make it look good.Another alternative is to use the persp3d function and surface3d functions in the rgl package. It would be quite tricky to get persp to handle hidden surfaces properly, whereas rgl will just do it (as long as neither is transparent. Transparency is hard.) For example, after running example(persp) so that x, y, and z contain values that were just used in persp(x, y, z, theta = 135, phi = 30, col = "green3", scale = FALSE, ltheta = -120, shade = 0.75, border = NA, box = FALSE) you can run library(rgl) persp3d(x,y,z, col="green3", aspect="iso", axes=FALSE, box=FALSE, xlab="", ylab="", zlab="") persp3d(x,y,(z + mean(z))/2, col="red", add=TRUE) and then rotate the surfaces to the desired viewing angle. Duncan Murdoch
The rgl package has an rgl.postscript function that should do that for you (I think there was a bug discovered and fixed recently, so make sure to get the latest version). -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow@intermountainmail.org (801) 408-8111 ________________________________ From: Roland Rau [mailto:roland.rproject@gmail.com] Sent: Friday, February 09, 2007 12:46 PM To: Duncan Murdoch Cc: Greg Snow; r-help Subject: Re: [R] two perspective plots in in plot Thanks Duncan and Greg. My current solution is to use the rgl-package. Is there an easy way to obtain a screenshot in eps- or pdf-Format from such an rgl-window? I saw the rgl.snapshot function but it does not provide this format. So far, I take a snapshot, save it as jpeg and convert it to eps via jpeg2ps.exe Maybe not the most elegant way but the results are better than I anticipated. Thanks, Roland On 2/9/07, Duncan Murdoch <murdoch@stats.uwo.ca> wrote: On 2/9/2007 1:11 PM, Greg Snow wrote: > Probably the easiest way is to use the "wireframe" function in the > lattice package. The second example in the help shows 2 surfaces (you > do need to combine the data into a single data frame). > > If you really want to use the "persp" function, then you could create > the first plot, then call "par(new=TRUE)" and then do the 2nd plot, but > that would take a lot of thinking to get the axes and scales to line up > properly and make it look good. Another alternative is to use the persp3d function and surface3d functions in the rgl package. It would be quite tricky to get persp to handle hidden surfaces properly, whereas rgl will just do it (as long as neither is transparent. Transparency is hard.) For example, after running example(persp) so that x, y, and z contain values that were just used in persp(x, y, z, theta = 135, phi = 30, col = "green3", scale = FALSE, ltheta = -120, shade = 0.75, border = NA, box FALSE) you can run library(rgl) persp3d(x,y,z, col="green3", aspect="iso", axes=FALSE, box=FALSE, xlab="", ylab="", zlab="") persp3d(x,y,(z + mean(z))/2, col="red", add=TRUE) and then rotate the surfaces to the desired viewing angle. Duncan Murdoch [[alternative HTML version deleted]]