title: ggplot scale color gradient to range outside of data range
body: <p>I am looking for a way to stretch a color gradient between two values and label the legend, regardless of the range of data values in the dataset. Essentially, is there a functional equivalent to <code>ylim()</code>  for color gradients? </p>
  
  <p>Given code which plots a z value typically between -1 and 1, I can plot and label a gradient if the breaks are within the data range:</p>
  
  <pre><code>library(ggplot2)
  
  #generator from http://docs.ggplot2.org/current/geom_tile.html
  pp &lt;- function (n, r = 4) { 
    x &lt;- seq(-r * pi, r * pi, len = n)
    df &lt;- expand.grid(x = x, y = x)
    df$r &lt;- sqrt(df$x^2 + df$y^2)
    df$z &lt;- cos(df$r^2) * exp(-df$r / 6)
    return(df)
  }
  
  t &lt;- pp(30)
  summary(t)
  b &lt;- c(-.5, 0, .5)
  colors &lt;- c('navyblue', 'darkmagenta', 'darkorange1')
  p &lt;- ggplot(data = t, aes(x = x, y = y))+
    geom_tile(aes(fill = z))+
    scale_fill_gradientn(colors = colors, breaks = b, labels = format(b))
  ggsave(plot = p, filename = &lt;somefile.png&gt;, height = 3, width = 4)
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/XQi3U.png" alt="graham jeffries ggplot scale fill example"></p>
  
  <p>But when I change the breaks to values outside of the observed range, the gradient coloring doesn't seem to adjust and the gradient labels don't appear.</p>
  
  <pre><code>b &lt;- c(-3, 0, 3)
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/FD9DA.png" alt="graham jeffries ggplot scale fill example 2"></p>