[英]ggplot: gradient scale to diverge on specific break
I have this data:我有这个数据:
df <- data.frame(x = 1:10,
y = 1:10,
value = c(seq(from = 0.5, to = 3.2, length.out = 9), Inf))
which I want to plot with a gradient colour scale highlighting three break values:我想用突出显示三个中断值的渐变色标绘制:
breaks <- c(0.5,1,3.2)
I want the white
colour to highlight my middle breaking value (that is 1
) and then the other two to increase in intensity as they reach the two tails of the distribution.我希望
white
突出我的中间突破值(即1
),然后其他两个在到达分布的两个尾部时增加强度。 Yet this will plot然而这将绘制
require(ggplot)
ggplot(df, aes(x,y,colour=value)) + geom_point(size=10) +
scale_colour_gradientn(colours = c("red","white","blue"),
breaks = breaks, labels = format(breaks))
with white
centered on the mean/median value ( 1.85
). white
以平均值/中值 ( 1.85
) 为中心。 I don't understand what's the point in declaring break points then.我不明白宣布断点有什么意义。
You could use scale_colour_gradient2
instead of scale_colour_gradientn
:您可以使用
scale_colour_gradient2
而不是scale_colour_gradientn
:
ggplot(df, aes(x,y,colour=value)) +
geom_point(size=10) +
scale_colour_gradient2(low = "red", mid = "white", high = "blue", midpoint = 1, breaks = breaks) +
theme_bw()
this gives:这给出:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.