0

I have created a heat map using geom_tile with a legend that shows the values of the colour gradient, with the following code:

scale_fill_gradient2(name = "log2(fold change)",
                             low = "navy",
                             mid = "white",
                             midpoint = 0,
                             high = "red",
                             breaks = c(-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4),
                             limits = c(-9,5),
                             guide = guide_colorbar(frame.colour = "black", 
                                                    ticks.colour = "black",
                                                    barheight = 13.5))

This is what I get:

enter image description here

I have noticed that the red colour at the top range is not as it should be for high = "red". When I extend the limit to +9 (limits = c(-9,9))I can see that the specified colour at the top range is correct:

enter image description here

How can I set the true red colour at upper limit 5?

Axeman
  • 32,068
  • 8
  • 81
  • 94
justinian482
  • 845
  • 2
  • 10
  • 18
  • Sorry I forgot to change that in the example code (I edited the original post to show the values of the breaks) – justinian482 Jul 14 '20 at 17:20
  • 2
    For asymmetric values around a midpoint you'll want `scale_fill_gradientn()` and the `scales::rescale()` convenience function. See, e.g., [this answer](https://stackoverflow.com/a/11301413/2461552). – aosmith Jul 14 '20 at 17:59
  • 1
    That looks like a perfect duplicate to me. Let me know if that did not solve your problem. – Axeman Jul 14 '20 at 18:03
  • Thanks that seems to solve it. – justinian482 Jul 14 '20 at 22:43

0 Answers0