简体   繁体   中英

asymmetric color distribution in scale_gradient2?

Changing the upper limits for scale_fill_gradient2 also effects the colorscaling for values < 0 as the color distribution around 0 seems to be always symmetrically, is there a way to get a asymmetric distribution of color values?

Here a minimal example of a plot using geom_tile() :

data <- read.csv("http://protzkeule.de/data.csv")
p <- ggplot(data = data, aes(x = variable, y = meas)) + geom_tile(aes(fill = value))

plot with symmetrical limits:

p + scale_fill_gradient2(low = "blue", mid = "white", high = "red", guide = "colorbar",
                         limits = c(-0.1, 0.1))

but when changing the upper limit, the lower colormapping changes as well (watch the colorbar):

p + scale_fill_gradient2(low = "blue", mid = "white", high = "red", guide = "colorbar",
                         limits = c(-0.1, 0.3))

What you want is scale_fill_gradientn . The arguments are not very clear (took me an hour or so to finally figure part of it out), though:

library("scales")
p + scale_fill_gradientn(colours = c("blue","white","red"), 
                         values = rescale(c(-.1,0,.3)),
                         guide = "colorbar", limits=c(-.1,.3))

Which gives:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM