13.9 Saving a Three-Dimensional Plot

13.9.1 Problem

You want to save a three-dimensional plot created with the rgl package.

13.9.2 Solution

To save a bitmap image of a plot created with rgl, use rgl.snapshot(). This will capture the exact image that is on the screen:

You can also use rgl.postscript() to save a PostScript or PDF file:

PostScript and PDF output does not support many features of the OpenGL library on which rgl is based. For example, it does not support transparency, and the sizes of objects such as points and lines may not be the same as what appears on the screen.

13.9.3 Discussion

To make the output more repeatable, you can save your current viewpoint and restore it later:

To save view in a script, you can use dput(), then copy and paste the output into your script:

Once you have the text representation of the userMatrix, add the following to your script: