ggcube

[R PACKAGE] A ggplot2 extension for 3D visualization

ggcube example

Overview

ggcube is an R package I developed to extend ggplot2’s native capabilities into the third dimension. While there are numerous 3D visualization libraries in R, none of them seamlessly integrate with the elegant grammar of graphics approach that makes ggplot2 so powerful and intuitive.

The package provides a framework where users can define 3D projections and then use familiar ggplot2 syntax alongside specialized projection functions to create sophisticated 3D visualizations. Rather than introducing a completely new paradigm, ggcube builds upon the existing ggplot2 foundation, allowing users to leverage their existing knowledge while adding the power of the z-axis.

This project emerged from my own need for high-quality, customizable 3D visualizations that maintain the aesthetic consistency and programmatic flexibility of the tidyverse ecosystem. While still under active development, the package already supports a range of projection types, visualization approaches, and customization options.

Key Features

  • Flexible 3D projections including orthographic, perspective, and various oblique projections
  • Full customization of rotation angles with pitch, roll, and yaw parameters
  • Compatible with ggplot2 geoms for seamless integration with familiar plotting components
  • Specialized 3D-specific layers such as:
    • proj_data() for projecting points, lines, and other geoms
    • proj_surface() for rendering 3D surfaces
    • proj_ridgeline() for creating Joy Division-style ridgeline plots
    • proj_margin() for adding marginal plots on cube faces
    • proj_panel() and proj_gridlines() for cube structure and reference lines
    • proj_label() for axis labeling

Applications

The package is useful for:

  • Creating publication-quality 3D visualizations with the familiar ggplot2 syntax
  • Rendering complex 3D surfaces and topographies
  • Visualizing multivariate data with color, size, and depth encoding
  • Building custom 3D visualizations for specific domains
  • Teaching and demonstrating 3D concepts with clear, aesthetic graphics

Resources

The package is currently under active development and hasn’t been released to CRAN yet. 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