jamesgiacmo at aol.com
2009-Oct-25 13:10 UTC
[R] Trying to save both an rgl plot and a bar plot errors
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 ) # [[alternative HTML version deleted]]
Peter Ehlers
2009-Oct-25 16:35 UTC
[R] Trying to save both an rgl plot and a bar plot errors
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. > >
David Winsemius
2009-Oct-25 16:53 UTC
[R] Trying to save both an rgl plot and a bar plot errors
On Oct 25, 2009, at 9:10 AM, 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 >library(rgl)> # PLOT > open3d()#which opens a graphics device of its own.> dev.new()#which opens another> setwd(...) # why? > plot3d(SN_PCA_All, col=rainbow(nrow(SN_PCA_All)))Error in plot3d(SN_PCA_All, col = rainbow(nrow(SN_PCA_All))) : object 'SN_PCA_All' not found> decorate3d(main ="SN_All_Ca") > barplot(SN_Scree_All_Percent[,1], main = "SN_All_Ca") > savePlot(filename = "01 +S+Na_AllCa_Scree", type ="tiff")Wouldn't you want to close the first and second devices before opening a third one?> rgl.viewpoint(180,0)Did your read the part of the help page that says: "We recommend that you avoid mixing rgl.* and *3d calls."> rgl.snapshot("01 +S+Na_AllCa_PCA.png", fmt="png", top=TRUE )I get the idea that you need to read more about graphics devices in R. You have multiple devices open at once and it is not clear where the output would be going.> # > > [[alternative HTML version deleted]]Since you are posting in HTML, you also have may not have read the part of the posting guide where is suggests that a working example should be included. I could be wrong and that SN_PCA_All dataset could be part of some package, in which case it would be good manners to include the name of that package. I am willing to give a shot at seeing if the 32 bit version of R on Leopard would run a complete example, and do some experimentation, but I am not willing to guess at what your data looks like. (The savePlot documentation on my Mac suggests that you should have opened up an X11 cairo device with type="cairo" rather than the (default) quartz device that dev.new() would typically open.) ?savePlot You should probably explain why you are using savePlot, since, on the Mac anyway, there are already tiff and png devices that may not get hung up with potential X11 confusion. ?png ?tiff # same help page #####------------------------------------------------------------------ ######> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html#####------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-######> > and provide commented, minimal, self-contained, reproducible code.^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -- David Winsemius, MD Heritage Laboratories West Hartford, CT
Duncan Murdoch
2009-Oct-25 19:10 UTC
[R] Trying to save both an rgl plot and a bar plot errors
On 25/10/2009 9:10 AM, 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.rgl relies on the graphics device driver for some of this work. If you find it works outside a loop but not inside one, maybe you just need to introduce a delay using sleep() to let the hardware/device driver catch up. 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 don't know what you mean here, but it sounds as though you think loading the image will show a figure. In this context, "image" is not something visual, it's just a copy of the R objects in your workspace. 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 ThomasCan't help you with that one.> > # 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 ) #I'd avoid putting spaces in filenames; in most situations it's fine, but occasionally you'll run across software that doesn't work properly with them. I don't think that's involved in the problems you saw above. Duncan Murdoch> > [[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.