2

在下面的示例中,一个 3 列和 5 行的矩阵。当我创建热图时,任何具有类似数字的行,如下例 (0.3,0.3,0.3),它在热图中显示白色。我的意图是将其更改为任何理想的颜色。示例:这是一个示例:

    A = matrix(c(0.0183207, 0.0000000, 0.1468750, 0.03, 0.03, 0.03,0.4544720,0.0000000,0.1395850,0.002,0,0,1.1,1,1),nrow=5,ncol=3,byrow = TRUE) 
dimnames(A) = list(c("row1", "row2","row3","row4","row5"),c("col1", "col2", "col3"))
heatmap.2( A,col =redgreen, scale = "row", cexRow=0.3, cexCol=0.8, margins=c(6,6), trace="none")

在示例中,我们看到一行是白色的,它来自行数据 (0.3,0.3,0.3)

非常感谢你的帮助

4

2 回答 2

4

The color is white because your heatmap command scales the rows before drawing the heatmap. So the row c(0.3, 0.3, 0.3) becomes a row of zeroes and zero is denoted by white in this color scheme.

If you want some other color scheme for these rows you must either think if you really want to scale the rows or play with the breaks and col arguments to create separate color for value 0.

于 2013-10-29T08:18:51.637 回答
2

当你缩放一个常数向量时会发生什么?你告诉 R 除以 0,得到你NaN

scale(c(0.3, 0.3, 0.3))

当您告诉heatmap.2按行缩放时会发生这种情况,但是其中一行没有变化。由于NaN不是数字,因此它被绘制为白色。如果您想将其涂成黑色,那么我认为您应该事先手动缩放数据,并将NaN's 替换为 0。

scaled_A <- t(apply(A, MARGIN=1, FUN=scale))
scaled_A[is.nan(scaled_A)] <- 0

然后你可以做热图调用

heatmap.2( scaled_A,col =redgreen,
           scale = "none",
           cexRow=0.3, cexCol=0.8,
           margins=c(6,6), trace="none",
           dendrogram='none')

而且是黑色的。它似乎按原样切换顺序,但您可能会弄清楚如何解决这个问题。

于 2013-10-29T19:22:30.873 回答