I\'m looking for an automatic way of highlighting some portions of the plot that have Station2
values greater than a pre-defined threshold which is 0 in this case.
Something like:
library(dplyr)
dateRanges <- df %>%
mutate(Date2 = lead(Date)) %>%
filter(key == 'Station2', value > 0 | lead(value) > 0, Date2 - Date == 1)
gg1 +
geom_rect(data = dateRanges,
aes(xmin = Date, xmax = Date2, ymin = -Inf, ymax = Inf),
inherit.aes = FALSE,
color = NA,
fill = 'grey20',
alpha = 0.2)
It's easiest to just draw one rect
for per day.