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

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

问题描述

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



这里是使用 geom_tile()

  data<  -  read.csv ://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( -  1,.1))

但是当更改上限时,较低的色彩映射也会更改(查看色条):

  p + scale_fill_gradient2(low =blue,mid =white,high =red,guide =colorbar,limits = c 1,.3))


解决方案

code> scale_fill_gradientn 。虽然:

 图书馆scales)
p + scale_fill_gradientn(colors = c(blue,white,red),
values = rescale(c( - 1,0,.3)),
guide =colorbar,limits = c( - 。1,.3))

其中包含:



p>

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(-.1,.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(-.1,.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:

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

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