gpt4 book ai didi

r - ggplot : gradient scale to diverge on specific break

转载 作者:行者123 更新时间:2023-12-04 07:20:46 26 4
gpt4 key购买 nike

我有这个数据:

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

enter image description here

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

这给出:

enter image description here

关于r - ggplot : gradient scale to diverge on specific break,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30639063/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com