title: ggplot2: Multiple color scales or shift colors systematically on different layers?
body: <p>When I make box plots, I like to also show the raw data in the background, like this:</p>
  
  <pre><code>library(ggplot2)
  library(RColorBrewer)
  
  cols = brewer.pal(9, 'Set1')
  
  n=10000
  dat = data.frame(value=rnorm(n, 1:4), group=factor(1:4))
  
  ggplot(dat, aes(x=group, y=value, color=group, group=group)) +
    geom_point(position=position_jitter(width=0.3), alpha=0.1) +
    scale_color_manual(values=cols) +
    geom_boxplot(fill=0, outlier.size=0)
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/vVDYF.png" alt="enter image description here"></p>
  
  <p>However, I don't like it how my box plots completely disappear when the points get too dense. I know I can adjust <code>alpha</code>, which is fine in some cases, but not when my groups have varying densities (For example when the lightest group would completely disappear if I were to decrease <code>alpha</code> enough so that the darkest group doesn't obscure the box plot). What I'm trying to do is systematically shift the colors for the box plots - a bit darker, perhaps - so that they show up even when the background points max out the alpha. For example:</p>
  
  <pre><code>plot(1:9, rep(1, 9), pch=19, cex=2, col=cols)
  cols_dk = rgb2hsv(col2rgb(brewer.pal(9, 'Set1'))) - c(0, 0, 0.2)
  cols_dk = hsv(cols_dk[1,], cols_dk[2,], cols_dk[3,])
  points(1:9, rep(1.2, 9), pch=19, cex=2, col=cols_dk)
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/Ryq9o.png" alt="enter image description here"></p>
  
  <p>So far I haven't found a way to fake in a different <code>scale_color</code> for the <code>geom_boxplot</code> layer (which would seem the simplest route if there's a way to do it). Nor have I been able to find a simple syntax to systematically adjust the colors the same way you can easily offset a continuous aesthetic like <code>aes(x=x+1)</code>.</p>
  
  <p>The closest thing I've been able to get is to completely duplicate the levels of the factor...</p>
  
  <pre><code>ggplot(dat, aes(x=group, y=value, color=group, group=group)) +
    geom_point(position=position_jitter(width=0.3), alpha=0.1) +
    scale_color_manual(values=c(cols[1:4], cols_dk[1:4])) +
    geom_boxplot(aes(color=factor(as.numeric(group)+4)), fill=0, outlier.size=0)
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/sypir.png" alt="enter image description here"></p>
  
  <p>but then I have to deal with that ugly legend. Any better ideas?</p>