相关疑难解决方法(0)

ggplot2热图,带有远程值的颜色

我想在ggplot2中制作热图.我的玩具数据和代码是:

set.seed(12345)
dat <- 
  data.frame(
      Row = rep(x = LETTERS[1:5], times = 10)
    , Col = rep(x = LETTERS[1:10], each = 5)
    , Y = rnorm(n = 50, mean = 0, sd = 1)
    )
library(ggplot2)
p <- ggplot(data =  dat, aes(x = Row, y = Col)) + 
      geom_tile(aes(fill = Y), colour = "white") +
      scale_fill_gradient(low = "white", high = "steelblue")
p
Run Code Online (Sandbox Code Playgroud)

我希望为这样的范围值设置颜色方案:

-3 <= Y < -2  ---> Dark Blue
-2 <= Y < -1  ---> Blue
-1 <= …
Run Code Online (Sandbox Code Playgroud)

r heatmap ggplot2

26
推荐指数
2
解决办法
5万
查看次数

标签 统计

ggplot2 ×1

heatmap ×1

r ×1