[R] Trying to save both an rgl plot and a bar plot errors

Peter Ehlers ehlers at ucalgary.ca
Sun Oct 25 17:35:32 CET 2009


jamesgiacmo at aol.com wrote:
> Hello,
> I am basically using a script that is designed to first create an rgl 3d scatter plot followed by a barplot on the same data. After this is done, the program is to first save the barplot as a .tiff file then to save the rgl 3d graph as a .png file. Once this is done, it is to repeat this 3d plot and barplot combo with saving 49 more times. The plotting script excerpt will be posted at the end of this email, and yes, the "setwd(...)" command is used correctly in the script just censored here. I have basically had problems with this script in three different ways.
>  In Windows Vista Home Premium, all 50 graph pairs are generated and the barplots are saved just fine as .tiff files, but the rgl .png files are saved as a giant black square instead of a graph. The other problem with Vista is that when I save the workspace image, it does not reload when I intentionally load the image. There are no error messages, all console evidence shows that the image loaded just fine but nothing shows up. I have also tried this on Mac OSX Snow Leopard (10.6). The machine stops after the first barplot is generated and states that there is an error in the 'savePlot' command and that X11(type ="*cairo") is not understood or something to the effect [I do not have the Mac with me at the time]. The script just stops after this error, so I do not know if the rgl or the .Rimage files save properly yet. 
> Thank you for your time,
> James Thomas
> 
> # PLOT  
> open3d()
> dev.new()
> setwd(...)
> plot3d(SN_PCA_All, col=rainbow(nrow(SN_PCA_All)))
> decorate3d(main ="SN_All_Ca")
> barplot(SN_Scree_All_Percent[,1], main = "SN_All_Ca")
> savePlot(filename = "01 +S+Na_AllCa_Scree", type ="tiff")
> rgl.viewpoint(180,0)
> rgl.snapshot("01 +S+Na_AllCa_PCA.png", fmt="png", top=TRUE )
> #

You don't provide reproducible code, so I have no idea where
your code goes off the rails.

I had no trouble (Vista) with the following, using data from
the examples on the help pages:

for(i in 1:3){
   open3d()
   x <- sort(rnorm(1000))
   y <- rnorm(1000)
   z <- rnorm(1000) + atan2(x,y)
   plot3d(x, y, z, col=rainbow(1000))

   tN <- table(Ni <- stats::rpois(100, lambda=5))
   r <- barplot(tN, col=rainbow(20))

   savePlot(filename = paste("barplot", i, sep=""), type ="tiff")

   rgl.viewpoint(180,0)
   rgl.snapshot(filename = paste("rgl", i, ".png", sep=""), fmt="png")
   graphics.off()
   rgl.close()
}

[I don't understand why you mix your rgl and traditional plotting,
but I suppose that you have your reasons.]

- Peter Ehlers

> 
> 	[[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