Intro Thoughts

Status Quo

library(tidyverse)
names(ggplot2::StatCount)
## [1] "default_aes"   "extra_params"  "super"         "compute_group"
## [5] "required_aes"  "setup_params"  "dropped_aes"
StatPie <- ggproto("StatPie", StatCount)

ggplot(diamonds) + 
  aes(y = .5, fill = cut) + 
  layer(geom = "bar", stat = "pie", position = "stack") + 
  coord_polar()

ggplot2::StatCount$default_aes
## Aesthetic mapping: 
## * `x`      -> `after_stat(count)`
## * `y`      -> `after_stat(count)`
## * `weight` -> 1
StatPie$default_aes <- aes(x = after_stat(count), y = .5, weight = 1)

ggplot(diamonds) + 
  aes(y = .5, fill = cut) + 
  layer(geom = "bar", stat = "pie", position = "stack") + 
  coord_polar()

ggplot(diamonds) + 
  aes(fill = cut) + 
  layer(geom = "bar", stat = "pie", position = "stack") + 
  coord_polar()
## Error:
## ! Problem while computing stat.
## ℹ Error occurred in the 1st layer.
## Caused by error in `setup_params()`:
## ! `stat_pie()` requires an x or y aesthetic.
ggplot(diamonds) + 
  aes(fill = cut) + 
  layer(geom = "bar",  
        stat = "pie", 
        position = "stack",
        mapping = aes(y = .5)) + 
  coord_polar()

geom_pie <- function(...){
  
  aes_y = aes(y = .5)
  
  layer(geom = "bar",  
        stat = "pie", 
        position = "stack",
        mapping = aes(..., !!!aes_y), 
        params = list(...)) 
  
}


ggplot(diamonds) + 
  geom_pie() + 
  coord_polar()
## Warning in geom_pie(): All aesthetics have length 1, but the data has 53940 rows.
## ℹ Did you mean to use `annotate()`?

last_plot() + 
  aes(fill = color)

ggplot(diamonds) + 
  geom_pie(aes(fill = color)) + 
  coord_polar()
## Warning in geom_pie(aes(fill = color)): Ignoring unknown parameters: ``
## Error in `geom_pie()`:
## ! Problem while computing aesthetics.
## ℹ Error occurred in the 1st layer.
## Caused by error in `FUN()`:
## ! Unknown input: <uneval>

Experiment

Closing remarks, Other Relevant Work, Caveats