ggcube

[R PACKAGE] A ggplot2 extension for 3D visualization

ggcube example

Overview

ggcube is an R package I developed that lets you build 3D figures using ggplot2. While there are numerous 3D visualization libraries in R, none of them seamlessly integrates with ggplot2, which is limiting given ggplot’s elegance, flexibility, and widespread usage. ggcube aims to help fill this gap.

The package is based around coord_3d(), a coordinate function you add to a ggplot that lets you define rotation and projection parameters for plots with x, y, and z aesthetic variable. ggcube also provides a variety of 3D-specific geoms to render surfaces, prisms, points, and paths in 3D; it also works with some standard ggplot2 layer functions. You can control plot geometry with 3D projection parameters, can apply a range of 3D lighting models, and can mix 3D layers with 2D layers rendered on cube faces. Standard ggplot2 features like faceting, themes, scales, and legends work as expected.

ggcube example

Resources

The package is currently under active development and hasn’t yet been released to CRAN, though the API should be relatively stable at this point. You can install the development version from GitHub using devtools::install_github("matthewkling/ggcube"). The GitHub repository contains additional examples and documentation.

The images on this page are examples of ggcube in action; see the GitHub page for the associated code.

ggcube example