yhat / ggpy

ggplot port for python
http://yhat.github.io/ggpy/
BSD 2-Clause "Simplified" License
3.7k stars 571 forks source link

scale_color_gradient2 should allow midpoint to be specified. #363

Open IamJeffG opened 10 years ago

IamJeffG commented 10 years ago

Function scale_color_gradient2 should take the data value to which the color mid should be set. In ggplot2 you pass this value as midpoint:

p = ggplot(aes(x='depth', y='price', colour='price'), data=diamonds) + geom_point() +
print(p + scale_colour_gradient2(low='blue', mid='white', high='red', \
                                 midpoint=diamonds.price.mean()))

Most of the time I use diverging colors in plotting bias values around a 0 midpoint, and indeed ggplot2 uses 0 as the default midpoint. A consequence is that if all your data values on the color aesthetic are positive and if you don't pass a midpoint (default 0) you will merely get a 2-color smooth gradient. This is a smart default: when using a diverging color gradient (scale_color_gradient2) the value from which the colors diverge (i.e. which value means "no effect") is the most important semantic aspect of the color ramp.

Possibly related: I notice Python's ggplot documentation says that scale_color_gradient2 takes a limits argument, but I don't see it make any difference in my plots. I might guess that limits was intended to allow the library to infer the midpoint, but (1) it doesn't do that, and anyway (2) I don't see this being practical for the user; the desired midpoint is rarely the mean or median of my data range.

has2k1 commented 10 years ago

This will be available in PR #360.