How to insert annotation on the very top facet of ggplot in R?

I would like to have the annotation on the very first facet of the following ggplot. right now, the code draws annotation on all facets. Anyway forward would be appreciate.

library(ggplot2)
library(lubridate)

set.seed(123)

DF <- data.frame(Date = seq(as.Date("2001-01-01"), to = as.Date("2005-12-31"), by = "1 month"),
                  Ob = runif(60,1,5), L95 =runif(60, 0,4), U95 = runif(60,2,7), Sim = runif(60,1,5)) %>% 
      pivot_longer(names_to = "Variable", values_to = "Value", -Date)

ggplot(data = DF, aes(x = Date))+
  geom_line(aes(y = Value))+
  facet_wrap(~ Variable, scales = "free_y", nrow = 4)+
  geom_vline(xintercept = as.Date("2004-12-01"),color = "red", size = 1.30)+
  annotate(geom = "text", x = as.Date("2002-01-01"), y = 3, label = "Calibration")+
  annotate(geom = "text", x = as.Date("2005-06-01"), y = 3, label = "Validation")

enter image description here



Read more here: https://stackoverflow.com/questions/64961319/how-to-insert-annotation-on-the-very-top-facet-of-ggplot-in-r

Content Attribution

This content was originally published by Hydro at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: