title: How do I adjust the scale of a geom_tile in ggplot2?
body: <p>I am trying to adjust the colour scale of a <code>geom_tile</code> plot.</p>
  
  <p>A short version of my data (in <code>data.frame</code> format) is:</p>
  
  <pre><code>mydat &lt;-
  
  Sc  K   n   minC
  A   2   1   NA
  A   2   2   37.453023
  A   2   3   23.768316
  A   2   4   17.628376
  A   3   1   NA
  A   3   2   12.693124
  A   3   3   8.884226
  A   3   4   7.436250
  A   10  1   2.128121
  A   10  2   2.116539
  A   10  3   2.737923
  A   10  4   3.509773
  A   20  1   1.104592
  A   20  2   1.840195
  A   20  3   2.717198
  A   20  4   3.616501
  B   2   1   NA
  B   2   2   25.090085
  B   2   3   15.924186
  B   2   4   11.811022
  B   3   1   NA
  B   3   2   8.827183
  B   3   3   6.179484
  B   3   4   5.175331
  B   10  1   2.096934
  B   10  2   2.064984
  B   10  3   2.662373
  B   10  4   3.407246
  B   20  1   1.096871
  B   20  2   1.802418
  B   20  3   2.649153
  B   20  4   3.517776
  </code></pre>
  
  <p>My code to prepare the data to plot is the following:</p>
  
  <pre><code>mydat$Sc &lt;- factor(mydat$Sc, levels =c("A", "B"))
  mydat$K &lt;- factor(mydat$K, levels =c("2", "3","10","20"))
  mydat.m &lt;- melt(pmydat,id.vars=c("Sc","K","n"), measure.vars=c("minC"))
  </code></pre>
  
  <p>I want to plot with <code>geom_tile</code> the value of <code>minC</code> with <code>K</code> and <code>n</code> as axis and different facets for <code>Sc</code> with the following:</p>
  
  <pre><code>mydat.m.p &lt;- ggplot(mydat.m, aes(x=n, y=K)) 
  mydat.m.p + 
    geom_tile(data=mydat.m, aes(fill=value)) +
    scale_fill_gradient(low="palegreen", high="lightcoral") +
    facet_wrap(~ Sc, ncol=2)
  </code></pre>
  
  <p>This gives me a plot for each <code>Sc</code> factor. However, the colour scale does not reflect want I want to portray, because a few high values making low values all equal.</p>
  
  <p>I want to adjust to a relevant scale in 4 breaks, i.e., 1-2, 2-3, 3-5, >5.</p>
  
  <p>Looking at other questions there was a suggestion to use the <code>cut</code> function and scale fill manual as:</p>
  
  <pre><code>mydat.m$value1 &lt;- cut(mydat.m$value, breaks = c(1:5, Inf), right = FALSE)
  </code></pre>
  
  <p>Then use the following in <code>geom_tile</code>:</p>
  
  <pre><code>scale_fill_manual(breaks = c("\[1,2)", "\[2, 3)", "\[3, 5)", "\[5, Inf)"),
  values = c("darkgreen", "palegreen", "lightcoral", "red"))
  </code></pre>
  
  <p>However, I am not sure how this can be applied to a <code>data.frame</code> with other factors and in long format.</p>