I can't seem to find a solution to my issue. I am plotting physicochemical properties of water over time. To make it easier to look at, I would like to change the background color of each summer, the graph spans on 3 years. This is my ggplot code at the moment:
ggplot(aes(x = Date_terrain, y = MSS, color = Num_cours, group = Num_cours), data = data.MSS) +
geom_point() +
geom_line() +
scale_x_date(date_breaks = "6 month",
labels=date_format("%d-%m-%Y"),
limits = as.Date(c('2016-06-01','2018-10-01')))
It works fine, albeit it isn't refined, but I can't seem to figure out how to do change. I tried with geom_rect
s but was only getting errors.
I'd like the background of each June 21st to September 22nd period grayed out.
Can let me know what function would be best for it?
Thank you very much.
dput:
structure(list(Date_terrain = structure(c(3L, 5L, 7L, 6L, 11L,
4L, 7L, 6L, 10L, 4L, 2L, 8L, 10L, 4L, 2L, 6L, 11L, 4L, 2L, 6L,
11L, 4L, 2L, 6L, 10L, 4L, 2L, 6L, 11L, 4L, 2L, 9L, 10L, 4L, 2L,
8L, 9L, 9L, 8L, 8L, 1L, 1L, 1L), .Label = c("", "04-06-17", "04-08-16",
"07-09-16", "09-09-16", "11-07-18", "14-07-17", "18-07-18", "19-07-18",
"20-07-16", "21-07-16"), class = "factor"), MSS = c(0L, 1L, 9L,
-6L, 2L, 1L, 9L, -6L, 6L, 2L, 11L, -6L, 6L, 1L, 4L, 8L, 1L, 1L,
6L, -6L, 1L, 1L, 7L, 8L, 2L, 1L, 5L, -7L, 1L, 3L, 8L, -8L, 1L,
3L, 12L, -3L, -6L, -7L, -4L, -6L, NA, NA, NA)), row.names = c(NA,
43L), class = "data.frame")
Current graph: