scale_gradient2 中的不对称颜色分布? [英] asymmetric color distribution in scale_gradient2?

查看:29
本文介绍了scale_gradient2 中的不对称颜色分布?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更改 scale_fill_gradient2 的上限也会影响值的颜色缩放0 因为 0 附近的颜色分布似乎总是对称的,有没有办法得到颜色值的不对称分布?

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?

这是一个使用 geom_tile() 的绘图的最小示例:

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))

具有对称限制的图:

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))

推荐答案

你想要的是scale_fill_gradientn.不过,这些论点不是很清楚(我花了一个小时左右才最终弄清楚其中的一部分):

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))

给出:

这篇关于scale_gradient2 中的不对称颜色分布?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆