繁体   English   中英

ggplot:渐变比例以在特定中断处发散

[英]ggplot: gradient scale to diverge on specific break

我有这个数据:

df <- data.frame(x = 1:10,
                 y = 1:10,
                 value = c(seq(from = 0.5, to = 3.2, length.out = 9), Inf))

我想用突出显示三个中断值的渐变色标绘制:

breaks <- c(0.5,1,3.2)

我希望white突出我的中间突破值(即1 ),然后其他两个在到达分布的两个尾部时增加强度。 然而这将绘制

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

在此处输入图片说明

white以平均值/中值 ( 1.85 ) 为中心。 我不明白宣布断点有什么意义。

您可以使用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()

这给出:

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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