title: Custom colours for geom_ribbon fill based for categorical data
body: <p>I'm trying to use custom colours defined in scale_colour_manual to fill a geom_ribbon in ggplot2. Here is an example I took from <a href="https://stackoverflow.com/questions/26396149/custom-ggplot2-shaded-error-areas-on-categorical-line-plot">Custom ggplot2 shaded error areas on categorical line plot</a>:</p>
  
  <pre><code>set.seed(12345)
  data &lt;- cbind(rep("A", 100), rnorm(100, 0, 1))
  data &lt;- rbind(data, cbind(rep("B", 100), rnorm(100, 5, 1)))
  data &lt;- rbind(data, cbind(rep("C", 100), rnorm(100, 10, 1)))
  data &lt;- rbind(data, cbind(rep("D", 100), rnorm(100, 15, 1)))
  data &lt;- cbind(rep(1:100, 4), data)
  data &lt;- data.frame(data)
  names(data) &lt;- c("num", "category", "value")
  data$num &lt;- as.numeric(data$num)
  data$value &lt;- as.numeric(data$value)
  data$upper &lt;- data$value+10
  data$lower &lt;- data$value-10
  
  data = data[order(data$category, data$num),]
  
  data$upperLoess = unlist(lapply(LETTERS[1:4], 
                                  function(x) predict(loess(data$upper[data$category==x] ~ 
                                                              data$num[data$category==x]))))
  data$lowerLoess = unlist(lapply(LETTERS[1:4], 
                                  function(x) predict(loess(data$lower[data$category==x] ~ 
                                                              data$num[data$category==x]))))
  
  ggplot(data, aes(num, value, colour=category, fill=category)) +
    scale_colour_manual(values = c("A"="black", "B"="red", "C"="magenta", "D"="green")) +
    geom_smooth(method="loess", se=FALSE) +
    geom_ribbon(aes(x=num, ymax=upperLoess, ymin=lowerLoess, fill=category),
                alpha=0.2)
  </code></pre>
  
  <p>Wrong color ribbons:
  <a href="https://i.stack.imgur.com/mmajw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mmajw.png" alt="enter image description here"></a></p>
  
  <p>Obviously, the colours defined for the categorical variable "category" are not used. Instead, the default palette (scale_colour_hue?) is used. I can place the fill argument outside the aes:</p>
  
  <pre><code>    ggplot(data, aes(num, value, colour=category, fill=category)) +
    scale_colour_manual(values = c("A"="black", "B"="red", "C"="magenta", "D"="green")) +
    geom_smooth(method="loess", se=FALSE) +
    geom_ribbon(aes(x=num, ymax=upperLoess, ymin=lowerLoess), fill="red", 
                alpha=0.2)
  </code></pre>
  
  <p>which results in red ribbons
  <a href="https://i.stack.imgur.com/hNYvd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hNYvd.png" alt="enter image description here"></a></p>
  
  <p>Any ideas? Thanks alot!</p>