Intro Thoughts

Status Quo

library(tidyverse)

Experiment

compute_group_chull <- function(data, scales){
  
  chull_ids <- chull(data$x, data$y)
  
  data[chull_ids,]
  
}

library(ggplot2)

StatChull <- ggproto("StatChull", Stat, compute_group = compute_group_chull)

palmerpenguins::penguins %>% 
  remove_missing() %>% 
  select(x = bill_length_mm, y = bill_depth_mm) %>% 
  compute_group_chull()
## Warning: Removed 11 rows containing missing values or values outside the scale
## range.
## # A tibble: 10 × 2
##        x     y
##    <dbl> <dbl>
##  1  59.6  17  
##  2  51.3  14.2
##  3  46.1  13.2
##  4  42.9  13.1
##  5  32.1  15.5
##  6  33.5  19  
##  7  34.6  21.1
##  8  46    21.5
##  9  54.2  20.8
## 10  55.8  19.8
palmerpenguins::penguins %>% 
  remove_missing() %>% 
  ggplot() + 
  aes(x = bill_length_mm, y = bill_depth_mm) + 
  geom_polygon(stat = StatChull)
## Warning: Removed 11 rows containing missing values or values outside the scale
## range.

GeomPolygon$default_aes
## Aesthetic mapping: 
## * `colour`    -> NA
## * `fill`      -> `from_theme(col_mix(ink, paper, 0.2))`
## * `linewidth` -> `from_theme(borderwidth)`
## * `linetype`  -> `from_theme(bordertype)`
## * `alpha`     -> NA
## * `subgroup`  -> NULL
GeomPolygonRed <- ggproto("GeomPolygonRed", 
                      GeomPolygon, default_aes = aes(color = "red"))



last_plot() +
  layer(GeomPolygonRed,
        StatChull,
        position = "identity")
## Warning: Using the `size` aesthetic in this geom was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` in the `default_aes` field and elsewhere instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

GeomPolygonRed2 <- ggproto("GeomPolygonRed2",
                           GeomPolygon,
                           default_aes = aes(colour    = "red",
fill     = from_theme(ggplot2:::col_mix(ink, paper, 0.2)),
linewidth = from_theme(borderwidth),
linetype  = from_theme(bordertype),
alpha     = NA,
subgroup  = NULL))



GeomPolygonRed2 <- ggproto("GeomPolygonRed2", GeomPolygon)
GeomPolygonRed2$default_aes$colour <- "red"

  
GeomPolygonRed2$default_aes
## Aesthetic mapping: 
## * `colour`    -> "red"
## * `fill`      -> `from_theme(col_mix(ink, paper, 0.2))`
## * `linewidth` -> `from_theme(borderwidth)`
## * `linetype`  -> `from_theme(bordertype)`
## * `alpha`     -> NA
## * `subgroup`  -> NULL
last_plot() +
  layer(GeomPolygonRed2,
        StatChull,
        position = "identity")

Closing remarks, Other Relevant Work, Caveats