I am really new to R and trying to lean it myself but now I got stuck in a place. I have tried to add a shaded area to a facet but it adds a shaded area to every facet. I wanna highlight a time from 2017-08-08 to 2017-08-16 only and I don't know how to do it.
The code I have right now looks like this:
ggplot(data = Andmed3, aes(x= Aeg, y = arch, group = Prooviala)) +
stat_summary(geom = "errorbar",fun.data = mean_se, aes(group = Prooviala, color = Prooviala)) +
stat_summary(fun = mean,geom="line",lwd=1,aes (group= Prooviala, color = Prooviala)) +
stat_summary(geom = "point", fun = mean, shape = 16, size = 2, aes(color = Prooviala)) +
facet_grid(~Periood, scales = "free_x", space = "free_x") +
labs(x = "Kuupäev", y = "Arhede 16S rRNA geenikoopiate arv")+
theme_bw() +
theme(axis.text.x = element_text(angle = 30, hjust = 1)) +
scale_x_datetime(date_breaks = "1 week", date_labels = " %e %b %y") +
geom_rect(aes(xmin = as.POSIXct('2017-08-08', format = '%Y-%m-%d'),xmax = as.POSIXct('2017-08-16', format = '%Y-%m-%d'),ymin = -Inf,ymax = Inf), alpha = 0.2, fill = 'grey')
I need my graph to look like my second picture but just with the highlighted background in the first facet.
Can someone help me with the code?
Thank You!