小编Don*_*Don的帖子

为热图上的连续发散色标设置中点

我需要通过 ggplot2 调整热图的中点位置。我用谷歌搜索了一下,发现scale_fill_gradient2很合身,但颜色似乎与我要找的不匹配。我知道 z 需要从 0 到 1 的范围。下面的示例数据集生成:

library(ggplot2)
library(tibble)
library(RColorBrewer)

set.seed(5)
df <- as_tibble(expand.grid(x = -5:5, y = 0:5, z = NA))
df$z <- runif(length(df$z), min = 0, max = 1)
Run Code Online (Sandbox Code Playgroud)

我尝试用 绘图,scale_fill_gradient2但蓝色并没有像我想要的那样“暗”。

ggplot(df, aes(x = x, y = y)) + 
  geom_tile(aes(fill = z)) + 
  scale_fill_gradient2(
    low = 'red', mid = 'white', high = 'blue',
    midpoint = 0.7, guide = 'colourbar', aesthetics = 'fill'
  ) + 
  scale_x_continuous(expand = c(0, 0), breaks = unique(df$x)) + …
Run Code Online (Sandbox Code Playgroud)

r heatmap ggplot2

2
推荐指数
2
解决办法
2378
查看次数

标签 统计

ggplot2 ×1

heatmap ×1

r ×1