Creating 3D pie charts in ggplot2

I am looking to create a 3D pie chart using ggplot2. The only way I've seen this can be done is using the ggthreed package (https://coolbutuseless.github.io/2018/11/13/ggthreed-3d-pie-charts/).

I've tried running the source code for a faceted 3D plot as follows

library(ggthreed)
library(tidyverse)

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()

however, it gives the following error

Warning: Unknown or uninitialised column: 'subgroup'.

The plots also don't appear in the output (see below). Anyone know how to resolve this issue? (Or to create 3D pie charts in ggplot2 with a package different to ggthreed?

Rplot

It doesn't work because ggplot detects and suppresses code that commits crimes against visualization.

Okay, just kidding.

The message is a warning, rather than an error (in fact, that same warning occurred in the code posted by the package author on the page you linked to) and probably isn't related to the underlying problem you're experiencing.

I'm not sure why the pie charts aren't appearing. The examples provided by the package author no longer produce pie charts either. The package hasn't been updated in two years (see https://github.com/coolbutuseless/ggthreed) so it might just be that the package has a bug or has not kept up with changes to ggplot2 and/or threed.

Update: Looks like the author of ggthreed has just released ggrgl, a new, more general package for extending ggplot2 into the 3rd dimension: https://coolbutuseless.github.io/package/ggrgl/index.html.

3 Likes

3D plots can be very useful, it particularly the pie chart flavour that is commonly disfavoured...
rayshader was recently featured by Rstudio on their youtube....
(51) 3D ggplots with rayshader - Dr. Tyler Morgan-Wall - YouTube

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

Thanks @joels, I'll give ggrgl a shot! Otherwise I'll just avoid 3D plots altogether :sweat_smile: