I'm having trouble adding multiple annotations (using vectors) to a plot with facets.
For example:
library(tidyverse) # ggplot2_3.3.0
tibble(t = 1:100) %>%
crossing(id = LETTERS[1:2]) %>%
group_by(id) %>%
mutate(y = cumsum(rnorm(n()))) %>%
ggplot(aes(t, y)) + # perhaps add `group = id` if you don't facet by `id`
facet_wrap(vars(id)) + # (1)
annotate('rect', xmin = 20, xmax = 30, ymin = -Inf, ymax = Inf, fill = 'grey60') + # (2)
annotate('rect', xmin = 30, xmax = 40, ymin = -Inf, ymax = Inf, fill = 'grey70') + # (2)
annotate('rect', xmin = 40, xmax = 50, ymin = -Inf, ymax = Inf, fill = 'grey80') + # (2)
annotate('rect', xmin = 50, xmax = 60, ymin = -Inf, ymax = Inf, fill = 'grey90') + # (2)
# annotate('rect', ymin = -Inf, ymax = Inf, # (3)
# xmin = seq(20, by=10, len=4), # (3)
# xmax = seq(30, by=10, len=4), # (3)
# fill = paste0('grey', seq(60, by=10, len=4))) + # (3)
geom_line() +
theme_light()
The above code produces the desired plot (in particular, I want the same annotation on all facets). However, the annotate command is repeated four times; furthermore the help page for annotate says "the properties of the geoms are ... passed in as vectors".
So a natural thing to try is to comment out lines (2), and uncomment lines (3).
Unfortunately this generates the error
Error: Aesthetics must be either length 1 or the same as the data (8): fill
Note that if, in addition, you comment out line (1) (and optionally add group = id to the aesthetics) then it does not generate an error.

