我想在 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
我想为这样的范围值设置配色方案:
-3 <= Y < -2 ---> Dark Blue
-2 <= Y < -1 ---> Blue
-1 <= Y < 0 ---> Light Blue
0 <= Y < 1 ---> Light Green
1 <= Y < 2 ---> Green
2 <= Y <= 3 ---> Dark Green