[英]R: Dividing heat map using colors with geom_tile() and scale_fill_gradientn()
[英]Continuous scale fill gradientn with fixed cutoffs R
我不知道如何在渐变填充中定义固定截止。 这是 iris 数据的一个例子:
ggplot(iris, aes(x=Sepal.Length,
y=Sepal.Width,
fill=Petal.Length))+
geom_point(shape=21)+
scale_fill_gradientn(colors=c("white","black","darkred","red"))
在我的实际数据中,我有一个热图,其中包含许多值 0、1-10 之间的很多值,以及成百上千的一些异常值。
我希望渐变为:
我不想用 bin 将它转换为一个因子,因为我确实想保持连续梯度,尤其是在比例的低部分。
谢谢你的帮助
您必须为白色到红色生成具有颜色colorspace
的自己的颜色伙伴,但如果您对默认的蓝色或绿色没有问题,您可以使用scale_fill_binned()
开箱即用:
ggplot(iris, aes(x=Sepal.Length,
y=Sepal.Width,
fill=Petal.Length))+
geom_point(shape = 21, size = 4) +
scale_fill_binned(breaks = c(2, 5), type = "viridis")
https://ggplot2.tidyverse.org/reference/guide_coloursteps.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.