[R] Exporting interactive 3D plots with axes and labels
van Rijn, Peter
pvanrijn at ets.org
Fri May 13 14:48:04 CEST 2011
Snapsnot3d just creates a flat image. It is possible to export the actual interactive 3D plot and put in a PDF, just not with the axes and labels.
Thanks,
Peter
-----Original Message-----
From: Remko Duursma [mailto:remkoduursma at gmail.com]
Sent: Thursday, May 12, 2011 7:17 PM
To: van Rijn, Peter; r-help at r-project.org
Subject: Re: [R] Exporting interactive 3D plots with axes and labels
Does ?snapshot3d not do what you want? Or what do you mean by 'export' ?
remko
-------------------------------------------------
Remko Duursma
Research Lecturer
Hawkesbury Institute for the Environment
University of Western Sydney
Hawkesbury Campus, Richmond
Mobile: +61 (0)422 096908
www.remkoduursma.com
On Fri, May 13, 2011 at 6:47 AM, van Rijn, Peter <pvanrijn at ets.org> wrote:
> Hi,
>
> I have a question about exporting interactive 3D plots. I use the following code to plot a contour of a trivariate normal distribution:
>
> library(mvtnorm)
> library(rgl)
> library(misc3d)
>
> n=25
> x=seq(-3,3,length=n)
> X=cbind(rep(x,each=n**2),rep(rep(x,each=n),n),rep(x,n**2))
> p=array(dmvnorm(X,sigma=diag(3)*0.5+0.5),c(n,n,n))
>
> contour3d(p,x,x,x,level=mean(p))
> lim=c(-3,3)
> decorate3d(xlim=lim,ylim=lim,zlim=lim,xlab="Variable X",ylab="Variable Y",zlab="Variable Z")
>
> 1. I know thanks to Luke Tierney (www.stat.uiowa.edu/~luke/R/misc3d/misc3d-pdf/misc3d-pdf.pdf) how to export the 3D plot without the axes and labels with:
>
> dummy=function(...){
> contour3d(p,x,x,x,level=mean(p),scale = FALSE,...)
> }
>
> conts=dummy()
>
> saveTrianglesAsOFF <- function(scene, filename = "scene.OFF") {
> scene <- misc3d:::colorScene(scene)
> triangles <- misc3d:::canonicalizeAndMergeScene(scene, "color", "color2",
> "alpha", "col.mesh",
> "fill", "smooth")
> ve <- misc3d:::t2ve(triangles)
> f <- file(filename, open = "w")
> on.exit(close(f))
> write("OFF", f)
> write(c(ncol(ve$vb), ncol(ve$ib), 3 * ncol(ve$ib)), f, 3)
> write(ve$vb, f, 3)
> write(rbind(3, ve$ib - 1), f, 4)
> invisible(NULL)
> }
>
> saveTrianglesAsOFF(conts,"plot.OFF")
>
> However, I would like to have the axes and labels in the export as well. Simply adding the decorate3d to the dummy function does not work,
> nor does creating a separate dummy. (I do know how to combine multiple exports in Meshlab).
>
> Does anyone know how to do this in some way or the other, or is this simply not possible?
>
> Thanks,
>
> Peter van Rijn
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>
More information about the R-help
mailing list