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

David Winsemius dwinsemius at comcast.net
Sun Oct 25 17:53:40 CET 2009

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
> # 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.)


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.

?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

More information about the R-help mailing list