Home > front end >  Create automatically multiple rectangles between limit values - in ggplot R
Create automatically multiple rectangles between limit values - in ggplot R

Time:03-21

I would like to plot rectangles between specific values listed in a data frame, such as:

 Region <- c("A","B","A","B","A","C","B","C","A"),
  Lon <- c(31.03547, 37.25443, 65.97450, 69.90290, 101.77630,
                 105.32550, 148.86270, 147.72010, 146.10420)
  var1 <- rnorm(n = 9, mean = 15, sd = 100)
  regions <- data.frame(Region, Lon, var1)

This is an example where I show the region limits using geom_vline:

 ggplot(NULL) 
  geom_vline(data = regions, aes(xintercept=Lon, 
                                 linetype=region,
                                 color = region),
             size=0.6) 
  geom_point(data = regions, aes(x=Lon, y=var1, color=Region)) 
  theme_bw()

I want to plot background rectangles that would be limited by those verticle lines.

I tried to look at this previous question: enter image description here

  • Related