title: Problem with geom_rect/ annotate("rec") cause a shift in the graph
body: <p>I have a faceted graph, and all I want to do is have each facet with a different area of the background shaded- Here's the graph: </p>
  
  <p><a href="https://i.stack.imgur.com/P1Qvil.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/P1Qvil.png" alt="enter image description here"></a></p>
  
  <p>With both geom_rect and annotate("rect") when I try to plot different coordinates/ facet they just overlap on all of them like this: </p>
  
  <p><a href="https://i.stack.imgur.com/agmGIl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/agmGIl.png" alt="enter image description here"></a></p>
  
  <p>or cause the data to shift left and makes a massive gap on the x-axis where it places the rectangle like this:</p>
  
  <p><a href="https://i.stack.imgur.com/HhGXul.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HhGXul.png" alt="enter image description here"></a></p>
  
  <p>I have tried using a dataframe for both however this causes the shift in the graph too, and have tried all the suggested things I can find but with no luck, am hoping its a simple problem with the code.</p>
  
  <p>Help to either of these would be greatly appreciated, thanks so much in advance!</p>
  
  <p>My base code for the geom_rect graph is as follows;</p>
  
  <pre><code>rm(list=ls())
  library("ggplot2")
  data&lt;- read.csv("circadian_time_n8.csv", header = TRUE, sep=",")
  head(data)
  as.data.frame(data)
  data$id&lt;-factor(data$id)
  data$binary&lt;-factor(data$binary)
  
  ggplot(data, aes(x=factor(time), y=factor(binary)),fill="black")+
        geom_bar(stat='identity')+
        facet_wrap(~id,  ncol=1,strip.position = "right")+
        geom_rect(aes(xmin = "2000", xmax = "2400", ymin = 0, ymax = 2),
                  fill = "pink", alpha = 0.03)+
        scale_y_discrete(limits = c(0,2), breaks=c(0,1,2), label=c("Inactive", "walk", "run"))+
        scale_x_discrete(breaks=seq(1600,3200,100),
                         label=c("16:00", "17:00", "18:00", "19:00", "20:00","21:00", "22:00", "23:00","00:00", "01:00","02:00", "03:00","04:00", "05:00",    "06:00",    "07:00", "08:00"))+
        labs(x="Time", y="Activity level")+
        theme_bw()+
        theme(panel.border = element_blank())+
        theme(panel.grid.major = element_line(size = 1))+
        theme(axis.text.x = element_text(angle = 45, hjust = 1))
  </code></pre>
  
  <p>and for annotate("rect")</p>
  
  <pre><code>ggplot(data, aes(x=factor(time), y=factor(binary)),fill="black")+
    geom_bar(stat='identity')+
    facet_wrap(~id,  ncol=1,strip.position = "right")+
    scale_y_discrete(limits = c(0,2), breaks=c(0,1,2), label=c("Inactive", "walk", "run"))+
    scale_x_discrete(breaks=seq(1600,3200,100),
                     label=c("16:00", "17:00", "18:00", "19:00", "20:00","21:00", "22:00", "23:00","00:00", "01:00","02:00", "03:00","04:00", "05:00",    "06:00",    "07:00", "08:00"))+
    labs(x="Time", y="Activity level")+
    theme_bw()+
    theme(panel.border = element_blank())+
    theme(panel.grid.major = element_line(size = 1))+
    theme(axis.text.x = element_text(angle = 45, hjust = 1))+
    annotate("rect", xmin = "1930", xmax = "3030", ymin = 0,  ymax = 2,alpha=.2)
  </code></pre>
  
  <p>The dataframe that I have tried is formatted the same as suggested in this answer; <a href="https://stackoverflow.com/questions/25286629/different-geom-rect-objects-for-facets">Different geom_rect() objects for facets</a></p>
  
  <p>data;</p>
  
  <pre><code>&gt; str(data)
  'data.frame':   8153 obs. of  6 variables:
   $ X24hr   : Factor w/ 2046 levels "00:00:00","00:01:00",..: 546 547 548 549 550 551 552 553 554 555 ...
   $ id      : Factor w/ 8 levels "231","235","236",..: 6 6 6 6 6 6 6 6 6 6 ...
   $ bark    : num  29.3 35.3 18.7 20.7 11.5 ...
   $ activity: Factor w/ 3 levels "high activity",..: 1 1 1 1 1 3 3 3 3 1 ...
   $ binary  : Factor w/ 3 levels "0","1","2": 3 3 3 3 3 2 2 2 2 3 ...
   $ time    : int  1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 ...
  </code></pre>
  
  <p>shorter version of data because the data set is too large for here;</p>
  
  <pre><code>&gt; dput(data)
  structure(list(X24hr = structure(c(11L, 12L, 13L, 14L, 15L, 16L, 
  17L, 18L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 
  13L, 14L, 15L, 16L, 17L, 18L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 
  9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 1L, 2L, 3L, 
  4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 
  18L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 
  14L, 15L, 16L, 17L, 18L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 
  10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 1L, 2L, 3L, 4L, 
  5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 
  1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L), .Label = c("00:00:00", "01:00:00", 
  "02:00:00", "03:00:00", "04:00:00", "05:00:00", "06:00:00", "07:00:00", 
  "08:00:00", "09:00:00", "16:00:00", "17:00:00", "18:00:00", "19:00:00", 
  "20:00:00", "21:00:00", "22:00:00", "23:00:00"), class = "factor"), 
      id = structure(c(6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 
      6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 
      7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 1L, 1L, 1L, 1L, 
      1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 5L, 
      5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
      5L, 5L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
      4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
      3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
      2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("231", 
      "235", "236", "237", "263", "267", "269"), class = "factor"), 
      bark = c(29.2727, 10.5455, 0.3636, 2.5455, 0, 0, 0, 0.1818, 
      0, 0, 0, 2, 0, 0, 0, 1.4545, 8.3636, 11.8182, 0.7273, 6.7273, 
      1.6364, 0.1818, 0, 0, 0, 12.1818, 0.1818, 0, 1.0909, 0, 0, 
      0, 0.1818, 0, 2.1818, 12.1818, 0, 6.7273, 0, 0, 0, 11.4545, 
      0.3636, 0, 0, 0.7273, 4.1818, 19.0909, 4, 2.1818, 0, 0.1818, 
      4.5455, 5.2727, 9.4545, 50.5455, 10.1818, 9.2727, 0.7273, 
      0, 0.3636, 0, 0, 0, 0, 0.1818, 0.5455, 0, 42.3636, 0, 0.1818, 
      13.0909, 43.0909, 0, 3.8182, 0, 0, 0, 0, 1.2727, 0.5455, 
      0, 0.3636, 0, 3.0909, 0, 10.1818, 2, 5.2727, 2, 29.2727, 
      15.2727, 8.3636, 1.8182, 0, 5.4545, 0, 3.2727, 0.3636, 1.6364, 
      1.2727, 2.9091, 0.3636, 0, 0, 0, 1.4545, 6, 10.3636, 42.9091, 
      4.7273, 0, 0, 0, 16, 12.5455, 4.5455, 0.1818, 1.0909, 0, 
      0, 5.2727, 12.5455, 2.5455, 5.2727), activity = structure(c(1L, 
      1L, 3L, 3L, 2L, 2L, 2L, 3L, 2L, 2L, 2L, 3L, 2L, 2L, 2L, 3L, 
      3L, 1L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 1L, 3L, 2L, 3L, 2L, 2L, 
      2L, 3L, 2L, 3L, 1L, 2L, 3L, 2L, 2L, 2L, 1L, 3L, 2L, 2L, 3L, 
      3L, 1L, 3L, 3L, 2L, 3L, 3L, 3L, 3L, 1L, 1L, 3L, 3L, 2L, 3L, 
      2L, 2L, 2L, 2L, 3L, 3L, 2L, 1L, 2L, 3L, 1L, 1L, 2L, 3L, 2L, 
      2L, 2L, 2L, 3L, 3L, 2L, 3L, 2L, 3L, 2L, 1L, 3L, 3L, 3L, 1L, 
      1L, 3L, 3L, 2L, 3L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 
      3L, 3L, 1L, 1L, 3L, 2L, 2L, 2L, 1L, 1L, 3L, 3L, 3L, 2L, 2L, 
      3L, 1L, 3L, 3L), .Label = c("high activity", "inactive", 
      "low activity"), class = "factor"), binary = structure(c(3L, 
      3L, 2L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 
      2L, 3L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 3L, 2L, 1L, 2L, 1L, 1L, 
      1L, 2L, 1L, 2L, 3L, 1L, 2L, 1L, 1L, 1L, 3L, 2L, 1L, 1L, 2L, 
      2L, 3L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 2L, 2L, 1L, 2L, 
      1L, 1L, 1L, 1L, 2L, 2L, 1L, 3L, 1L, 2L, 3L, 3L, 1L, 2L, 1L, 
      1L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 3L, 2L, 2L, 2L, 3L, 
      3L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 
      2L, 2L, 3L, 3L, 2L, 1L, 1L, 1L, 3L, 3L, 2L, 2L, 2L, 1L, 1L, 
      2L, 3L, 2L, 2L), .Label = c("0", "1", "2"), class = "factor"), 
      time = c(1600L, 1700L, 1800L, 1900L, 2000L, 2100L, 2200L, 
      2300L, 2400L, 2500L, 2600L, 2700L, 2800L, 2900L, 3000L, 3100L, 
      3200L, 3300L, 1600L, 1700L, 1800L, 1900L, 2000L, 2100L, 2200L, 
      2300L, 2400L, 2500L, 2600L, 2700L, 2800L, 2900L, 3000L, 3100L, 
      3200L, 3300L, 1600L, 1700L, 1800L, 1900L, 2000L, 2100L, 2200L, 
      2300L, 2400L, 2500L, 2600L, 2700L, 2800L, 2900L, 3000L, 3100L, 
      3200L, 3300L, 1600L, 1700L, 1800L, 1900L, 2000L, 2100L, 2200L, 
      2300L, 2400L, 2500L, 2600L, 2700L, 2800L, 2900L, 3000L, 3100L, 
      3200L, 3300L, 1600L, 1700L, 1800L, 1900L, 2000L, 2100L, 2200L, 
      2300L, 2400L, 2500L, 2600L, 2700L, 2800L, 2900L, 3000L, 3100L, 
      3200L, 3300L, 1600L, 1700L, 1800L, 1900L, 2000L, 2100L, 2200L, 
      2300L, 2400L, 2500L, 2600L, 2700L, 2800L, 2900L, 3000L, 3100L, 
      3200L, 3300L, 1600L, 1700L, 1800L, 1900L, 2000L, 2100L, 2200L, 
      2300L, 2400L, 2500L, 2600L, 2700L, 2800L, 2900L, 3000L, 3100L, 
      3200L)), row.names = c(NA, -125L), class = "data.frame")
  
  &gt; str(data)
  'data.frame':   125 obs. of  6 variables:
   $ X24hr   : Factor w/ 18 levels "00:00:00","01:00:00",..: 11 12 13 14 15 16 17 18 1 2 ...
   $ id      : Factor w/ 7 levels "231","235","236",..: 6 6 6 6 6 6 6 6 6 6 ...
   $ bark    : num  29.273 10.546 0.364 2.546 0 ...
   $ activity: Factor w/ 3 levels "high activity",..: 1 1 3 3 2 2 2 3 2 2 ...
   $ binary  : Factor w/ 3 levels "0","1","2": 3 3 2 2 1 1 1 2 1 1 ...
   $ time    : int  1600 1700 1800 1900 2000 2100 2200 2300 2400 2500 ...
  </code></pre>
  
  <p>Thank you!!</p>