README.md

ggthreed - 3d geoms and stats for ggplot2

Travis build
status AppVeyor build
status

ggthreed is a collection of ggplot2 geoms which use the threed library.

What’s in the box:

Installation

You can install from github

# install.packages("devtools")
devtools::install_github("coolbutuseless/threed")
devtools::install_github("coolbutuseless/ggthreed")

Red/blue anaglyphs with stat_anaglyph()

Grab your glasses and lower your expectations!!

Usage

Example red/blue anaglyphs with points.

ggplot(mtcars) +
  geom_point(aes(mpg, y = wt, z = disp), stat = 'anaglyph', alpha = 0.5, zscale = 10) +
  theme_bw()

Example of combined 3d projection and anaglyph

library(threed)

camera_to_world <- look_at_matrix(eye = c(1.5, 1.75, 3), at = c(0, 0, 0))

obj <- threed::mesh3dobj$cube %>%
  transform_by(invert_matrix(camera_to_world)) %>%
  translate_by(c(0, 0, -3)) %>%
  perspective_projection()

ggplot(obj, aes(x, y, z = z, group = element_id)) +
  geom_polygon(fill = NA, colour='black', aes(size = hidden), stat = 'anaglyph',
               zscale = 0.05, zoffset = -1.4, zinvert = FALSE) +
  scale_linetype_manual(values = c('TRUE' = "FF", 'FALSE' = 'solid')) +
  scale_size_manual(values = c('TRUE' = 0.1, 'FALSE' = 0.5)) +
  theme_void() +
  theme(legend.position = 'none') +
  coord_equal()

Animated Anaglyph

Animated Icosahedron

See vignette('animated-anaglyph', package='ggthreed')

3d pie charts with geom_threedpie()

Usage

Issues/Limitations

Example - Simple Pie Chart

ggplot(mtcars) + 
  geom_threedpie(aes(x = as.factor(cyl))) + 
  theme_void() + 
  theme(legend.position = 'bottom')

Example - Facetted Pie Chart

ggplot(diamonds)  +
  geom_threedpie(aes(as.factor(cut))) +
  facet_wrap(~clarity, labeller = label_both) +
  labs(title = "Distribution of Diamond Cuts by Clarity") +
  scale_fill_brewer(name = "Cut", palette = 'Set2') +
  theme_void()

Example - Behind the Scenes

ggplot(mtcars) + 
  geom_threedpie(aes(x = as.factor(cyl)), alpha = 0.5) + 
  theme_void() + 
  theme(legend.position = 'bottom')

Example - Pie configuration

User adjustable:



coolbutuseless/ggthreed documentation built on May 16, 2019, 7:14 p.m.