title: Changing the background color of a ggplot chart with a factor variable
body: <p>I'm using <code>ggplot</code> in R in order to plot some data. What I am trying to do is have a scatter plot where the background is different in different regions of the chart. There is a very helpful answer <a href="https://stackoverflow.com/questions/9968975/using-ggplot2-in-r-how-do-i-make-the-background-of-a-graph-different-colours-in">here</a> that is getting me most of the way there but not all the way.</p>
  <p>Here is a sample of the data</p>
  <pre><code>row.names selectionDirector country     Totals    director.rank
  1   268   Alfred Hitchcock  Argentina   14        1
  2   269   Alfred Hitchcock  Australia   7         3
  3   274   Alfred Hitchcock  Canada      10        1
  4   286   Alfred Hitchcock  France      18        1
  5   288   Alfred Hitchcock  Germany     9         6
  6   296   Alfred Hitchcock  Italy       5         3
  7   319   Alfred Hitchcock  Spain       21        4
  8   320   Alfred Hitchcock  Sweden      4         8
  9   325   Alfred Hitchcock  UK          87        1
  10  330   Alfred Hitchcock  US          87        1
  11  346   Andrei Tarkovsky  Argentina   4         20
  12  347   Andrei Tarkovsky  Australia   2         34
  13  355   Andrei Tarkovsky  Canada      2         32
  14  365   Andrei Tarkovsky  France      2         37
  </code></pre>
  <p>My code is:</p>
  <pre><code>rects &lt;- data.frame(xstart = seq(-0.5,8.5,1), xend = seq(0.5,9.5,1), col = letters[1:10])
  
  ggplot() +
    geom_rect(data=rects,aes(ymin=0,ymax=80,xmin=xstart,xmax=xend,fill=col)) +
    geom_point(data=top.votes.by.director.country, aes(x=country, y=director.rank)) +
    coord_flip() +
    facet_wrap(~selectionDirector)
  </code></pre>
  <p>country is a factor with 10 values. <code>director.rank</code> is numeric. They both come from the data frame <code>top.votes.by.director.country</code>. The idea is to have a background that is different for the horizontal area for each country to make it easier to read when I facet.
  <img src="https://i.stack.imgur.com/IQR9U.png" alt="enter image description here" /></p>
  <p>Imagine the picture above except that instead of colored points, there would be a colored band behind a black point for each country. The closest approximation I can find online is the chart below taken from the answer from the link above:</p>
  <p><img src="https://i.stack.imgur.com/8zBF5.jpg" alt="enter image description here" /></p>
  <p>So there would be a colored background for each country in the faceted graph just as the chart above has a colored background for each region.</p>
  <p>The problem is that when I run the code above, I get the following error.</p>
  <blockquote>
  <p>Error: Discrete value supplied to continuous scale</p>
  </blockquote>
  <p>When I remove the <code>geom_rect</code> portion, it works fine. If I move the <code>geom_rect</code> above the <code>facet_wrap</code>, I get a chart, although it's messed up. If I do just the <code>geom_rect</code> part, I get the background I want approximately.</p>
  <p>I've been messing around with this for a couple of hours now and can't get it to work.</p>