Description
The current approach to repeating a layer across panels is to not have the layer data contain the variable needed for the faceting. This is an approach also implemented in gganimate when it comes to having layers be static across the animation. While this works intuitively, I feel it often requires some additional dataprep before the plotting code, and sometimes require that layers that otherwise use the same data need to target separate almost identical datasets.
Would it make sense to add a static
or perhaps repeat
argument to geom and stat functions to explicitly mark them for being repeated across panels (and frames in the case of gganimate)?
Example API:
library(dplyr)
library(ggplot2)
# Current approach
diamonds_static <- mutate(diamonds, cut = NULL)
ggplot(diamonds, aes(x = color)) +
geom_bar(data = diamonds_static, fill = 'grey70') +
geom_bar() +
facet_wrap(~cut)
# New approach
ggplot(diamonds, aes(x = color)) +
geom_bar(fill = 'grey70', static = TRUE) +
geom_bar() +
facet_wrap(~cut)
The "problem" with the current approach is that it requires changes to the data source if we decide to change the faceting variable — not a huge problem, but still a barrier to experimentation.
If the static
name is too close to the idea of animation, then we can figure out another name for it...