Intro Thoughts

Status Quo

library(tidyverse)

layers_wipe <- function(i = NULL) {

  structure(
    list(index_wipe = i), 
    class = "layers_wipe"
    )

}


ggplot_add.layers_wipe <- function(object, plot, object_name) {
  
  if(is.null(object$index_wipe)){
   
    plot$layers <- list()
     
  }else{
    
  plot$layers[object$index_wipe] <- NULL

  }
  
  plot
  
}

ggplot(cars) + 
  aes(speed, dist) + 
  geom_point() + 
  geom_tile()

last_plot() + 
  layers_wipe(i = 2)

last_plot() + 
  layers_wipe()

Experiment

(theme_bw() + 
  theme(geom = element_geom(pointshape = 21))) |>
  theme_set()

gapminder::gapminder |> 
  filter(year == 2002) |>
  ggplot() +
  aes(gdpPercap, lifeExp) + 
  geom_point() + 
  facet_wrap(facet = vars(continent)) + 
  layers_wipe() + 
  # drop shadow
  geom_point(data = . %>% select(-continent), 
             fill = "grey" |> alpha(.5)) + 
  # faceted
  geom_point() + 
  # styling
  aes(fill = I("plum4")) + 
  aes(color = I("white")) +
  aes(size = I(4))

Closing remarks, Other Relevant Work, Caveats