title: Manipulating the legend of scale_fill_gradient2
body: <p>I have data which comes from a statistical test (gene set enrichment analysis, but that's not important), so I obtain p-values for statistics that are normally distributed, i.e., both positive and negative values:</p>
  
  <p>The test is run on several categories:</p>
  
  <pre><code>set.seed(1)
  df &lt;- data.frame(col = rep(1,7), 
                   category = LETTERS[1:7], 
                   stat.sign = sign(rnorm(7)), 
                   p.value = runif(7, 0, 1), 
                   stringsAsFactors = TRUE)
  </code></pre>
  
  <p>I want to present these data in a <code>geom_tile</code> <code>ggplot</code> such that I color code the <code>df$category</code> by their <code>df$p.value</code> multiplied by their <code>df$stat.sign</code> (i.e, the sign of the statistic)</p>
  
  <p>For that I first take the <code>log10</code> of <code>df$p.value</code>:</p>
  
  <pre><code>df$sig &lt;- df$stat.sign*(-1*log10(df$p.value))
  </code></pre>
  
  <p>Then I <code>order</code> the <code>df</code> by <code>df$sig</code> for each sign of <code>df$sig:</code></p>
  
  <pre><code>library(dplyr)
  df &lt;- rbind(dplyr::filter(df, sig &lt; 0)[order(dplyr::filter(df, sig &lt; 0)$sig), ],
              dplyr::filter(df, sig &gt; 0)[order(dplyr::filter(df, sig &gt; 0)$sig), ])
  </code></pre>
  
  <p>And then I <code>ggplot</code> it:</p>
  
  <pre><code>library(ggplot2)
  df$category &lt;- factor(df$category, levels=df$category)
  
  ggplot(data = df,
         aes(x = col, y = category)) + 
    geom_tile(aes(fill=sig)) + 
    scale_fill_gradient2(low='darkblue', mid='white', high='darkred') + 
    theme_minimal() + 
    xlab("") + ylab("") + labs(fill="-log10(P-Value)") +
    theme(axis.text.y = element_text(size=12, face="bold"), 
          axis.text.x = element_blank())
  </code></pre>
  
  <p>which gives me:</p>
  
  <p><a href="https://i.stack.imgur.com/kpFnq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kpFnq.png" alt="enter image description here"></a></p>
  
  <p>Is there a way to manipulate the <code>legend</code> such that the values of <code>df$sig</code> are represented by their absolute value but everything else remains unchanged? That way I still get both red and blue shades and maintain the order I want.</p>