Home

Awesome

<!-- README.md is generated from README.Rmd. Please edit that file -->

ggrgl <img src="man/figures/logo.png" align="right" height=300 title="An homage to the old logo for the Berlin Hilton"/>

<!-- badges: start -->

Lifecycle:
experimental

<!-- badges: end -->

ggrgl extends ggplot2 into the third dimension.

ggrgl does this by adding a new z aesthetic which is respected when a plot is rendered to the {devoutrgl} device which renders to OpenGL via {rgl}.

Because {devoutrgl} is an interactive device, the view of the plot may be manipulated by the user - zoom, rotate, change field-of-view etc.

Slideshow

<img src="man/figures/examples.gif" width="85%" /> <!-- #### Example Gif --> <!-- <details open> --> <!-- <summary> Click to hide/reveal an animated gif of a 3d plot </summary> --> <!-- <img src="man/figures/anim1.gif" width="85%" /> --> <!-- </details> --> <!-- <br/> -->

Note: interactive 3d plots cannot be displayed in a github README file, and static images or animated gifs are used here instead.

Visit the pkgdown online documentation to view plots which can be manipulated in the browser.

Installation

A lot of support packages are needed for ggrgl - most of which should already be installed if you have ggplot.

Custom packages which are needed (and not currently on CRAN):

You can install from GitHub with:

# install.package('remotes')
remotes::install_github('coolbutuseless/devout')
remotes::install_github('coolbutuseless/devoutrgl')
remotes::install_github('coolbutuseless/triangular')
remotes::install_github('coolbutuseless/snowcrash')
remotes::install_github('coolbutuseless/cryogenic')
remotes::install_github('coolbutuseless/ggrgl', ref='main')

New z Aesthetic

The new z aesthetic works the same as the x and y aesthetics in ggplot2.

z may be mapped to a data variable or set to a constant.

New Extrusion Aesthetics

When graphical elements have a z value they are raised above the ground.

By setting extrude = TRUE (on geoms which support it), then the raised element is connected to the ground as if it were extruded from it.

New aesthetics control the appearance of the extruded faces and edges:

aestheticDescriptiondefault
extrude_zLower limit of extrusion0.05
extrude_face_fillExtruded face colourgrey20
extrude_face_alphaExtruded face alpha1
extrude_edge_colourEdge colour for extrusionNA
extrude_edge_alphaEdge alpha for extrusion1
extrude_edge_sizeWidth of line for extruded edges1

3-dimensional Geometry Types: z and 3d

ggrgl defines 2 classes of geoms: z and 3d

Click on a geom in the following table to view its vignette

ggplot2Planar Z offset3d
geom_bargeom_bar_z
geom_contourgeom_contour_z
geom_contour_filledgeom_contour_filled_z
geom_densitygeom_density_z
geom_linegeom_line_3d
geom_pathgeom_path_3d
geom_pointgeom_point_zgeom_sphere_3d
geom_polygongeom_polygon_z
geom_rectgeom_rect_z
geom_ribbongeom_ribbon_z
geom_segmentgeom_segment_3d
geom_textgeom_text_z
geom_tilegeom_tile_z

Vignettes

There are vignettes on all the new geoms in this package, see links in the table above or click on an image below

Some vignettes with some details of the implementation and usage are:

To see all vignettes see the online documentation

Dark Side of the MoonDNAPie
Joy DivisionVolcanoTerrain
BunnyCaffeine MoleculeUSA Map

Example - A Basic 3d Bar Plot with geom_bar_z()

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Always explicitly load required packages - there are some possible 
# issues if you don't!
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
suppressPackageStartupMessages({
  library(rgl)
  library(devout)
  library(devoutrgl)
  library(ggrgl)
  library(ggplot2)
})

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Use `geom_bar_z` and set `z` to 200 and use extrusion
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
p <- ggplot(mpg) +
  geom_bar_z(aes(x=class, fill=class), colour='black', z=200, extrude=TRUE)


#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Render Plot in 3d with {devoutrgl}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
devoutrgl::rgldev()
p
invisible(dev.off())
<img src="man/figures/readme-example-annotated.png" width="100%" />

Related Software

Acknowledgements