0

I want to plot a variable on a map, showing positive values in green and negative values in red.

I'm using ggplot2. First, I used this command :

scale_fill_gradient2(low="red",mid="white",high="green")

I obtained this result:

enter image description here

But I don't like the result. Most values are around 0, and the scale doesn't separate well these values : they are all white. So, I want to modify the scale, in order to show more diversity among values close to 0. In the ggplot2 scale documentation, there is an argument allowing to do that : values. But, this argument is working with scale_fill_gradientn, and not scale_fill_gradient2. So, I used this new function :

scale_fill_gradientn(colours = c("red", "white", "green"), values = scales::rescale(c(-1, -0.2, 0, 0.2, 1)))

enter image description here

Now it's better ! But there is one problem : the center of the scale (white colour) is no longer 0, it's around 5. And I don't know how to change that, because low/mid/high arguments I used in the previous plot are not working in scale_fill_gradientn function.. So my question is : how to use both mid and values arguments, in order to make a personalized scale in ggplot ?

yoshi8585
  • 103
  • 6
  • 1
    likely related https://stackoverflow.com/questions/49369372/how-to-make-ggplot-colorbar-change-asymmetrically-around-midpoint and https://stackoverflow.com/questions/11299705/asymmetric-color-distribution-in-scale-gradient2?noredirect=1&lq=1 – tjebo Feb 17 '20 at 14:37
  • I think your first plot is already pretty good. Setting the limits in `scale_fill_gradient2` to a smaller interval would possibly be a good option too – tjebo Feb 17 '20 at 14:40
  • P.S. You may want to use some other colors than those red and green, because for color blind people it can be really tricky to distinguish those – tjebo Feb 17 '20 at 14:44
  • Thank you for the answer ! I don't like the 1st plot, because minimum values are pale red, and not normal red as on the 2nd plot. – yoshi8585 Feb 17 '20 at 15:10
  • this should change when you specify the limits! – tjebo Feb 17 '20 at 15:37
  • Yes, I could use limits = c(-5,5) for example. But extreme values are colored in gray : it's not better. Morever, I think it's not very clear to show a [-5,5] legend, if the real interval of the variable isn't [-5,5] – yoshi8585 Feb 17 '20 at 15:44

0 Answers0