Building a rotating 3D graph and exporting it as a GIF
When dealing with complex datasets, having the possibility to show your data in a 3D environment can be really enhancing.
This recipe will show you how to create such a plot, animate it, and export your animation as a GIF.
Getting ready
This recipe will leverage the rgl
package specifically developed for 3D visualizations in R:
install.packages("rgl") library(rgl)
We will also need to install ImageMagick in order to perform the export into the GIF format.
You can find instructions for software installation at http://www.imagemagick.org/script/binary-releases.php.
As an explicative dataset, we will use the iris
dataset, which is a built-in dataset available with all base R installations.
The iris
dataset is one of the most used datasets in R tutorials and learning sessions, and it is derived from a 1936 paper by Ronald Fisher, named The use of multiple measurements in taxonomic problems.
Data was observed on 50 samples of 3 species...