【问题标题】:Continous scale fill gradientn with fixed cutoffs R具有固定截止 R 的连续缩放填充梯度
【发布时间】:2020-07-02 19:02:00
【问题描述】:

我不知道如何在渐变填充中定义固定截止。 This is an example on the iris data:

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 之间的很多值、成百上千的一些异常值。

我希望渐变是:

  • 0 = 白色
  • 1-10 = 从灰色到黑色
  • 11-100 = 从黑色到深红色
  • 101-1000 = 从深红色到红色
  • 超过 1000 = 紫色

我不想用 bin 将它转换成一个因子,因为我确实想保持连续梯度,尤其是在比例的低部分。

感谢您的帮助

【问题讨论】:

标签: r ggplot2 gradient


【解决方案1】:

您必须使用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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-24
    • 2018-05-12
    • 1970-01-01
    • 2023-03-15
    • 2020-01-31
    • 1970-01-01
    相关资源
    最近更新 更多