[R] Exporting interactive 3D plots with axes and labels

Remko Duursma remkoduursma at gmail.com
Fri May 13 01:17:12 CEST 2011


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