在 base R 中翻转热图的颜色范围

Flip color range of heatmap in base R

我正在 base R 中构建一个简单的热图。 这是我的矩阵:

stleft = matrix( 
     c(0,5,5,2,6,8,4,6,9), 
     nrow=3, 
     ncol=3) 
colnames(stleft) <- c("Narrow","Wide", "Wider")
rownames(stleft) <- c("Person", "Object","Bare")
stleft

矩阵如下所示:

> stleft
       Narrow Wide Wider
Person      0    2     4
Object      5    6     6
Bare        5    8     9

要构建热图,我只需 运行:

heatmap(stleft, Colv = NA, Rowv = NA, scale = "none")

如您所见,“0”(对应于 narrow/person 单元格)显示为深红色,而“9”(对应于 wider/bare 单元格)显示为浅黄色。

heatmap()(和image())默认使用heat.colors()生成颜色。如果需要,您可以提供自己的颜色,f.ex。通过使用 heat.colors(),正好相反。

par(oma=c(3, 0, 0, 3))
col <- rev(heat.colors(999))
heatmap(stleft, Colv = NA, Rowv = NA, scale = "none", col = col)