[英]Continuous scale fill gradientn with fixed cutoffs R
I can't figure out how to define fixed cutoffs in a gradient fill.我不知道如何在渐变填充中定义固定截止。 This is an example on the iris data:这是 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"))
In my actual data, I have a heatmap with many values 0, a lot between 1-10, a few outliers in the hundreds and thousands.在我的实际数据中,我有一个热图,其中包含许多值 0、1-10 之间的很多值,以及成百上千的一些异常值。
I would like the gradient to be:我希望渐变为:
I don't want to transform it in a factor with bins, because I do want to maintain the continuous gradient especially at the low parts of the scale.我不想用 bin 将它转换为一个因子,因为我确实想保持连续梯度,尤其是在比例的低部分。
Thank you for you help谢谢你的帮助
You will have to generate you own color pal with colorspace
for the white to red, but if you're okay with the default blues or viridis, you can have that out of the box with scale_fill_binned()
:您必须为白色到红色生成具有颜色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 https://ggplot2.tidyverse.org/reference/guide_coloursteps.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.