R 热图:隐藏单元格值 = 0 的单元格注释

R Heatmap: Hide cellnote for cell value = 0

我有一个可用的热图,使用 gplots 构建,如下所示:

heatmap.2(as.matrix(matrix1),cellnote=as.matrix(matrix1),
    notecol="black",margins =c(9,6),trace="none",density.info="none",
    col=my_palette,Rowv=NA,Colv=NA,dendrogram="none",scale="row")

matrix1 中的基础数据如下所示:

A       AA        AAA        BBB         CASH

CASH    0         0          0           0
JSUB    0.22171   0          0           2.20712
SECR    2.92828   1.97112    3.53786     0.91444
SENR    18.86672 11.53339   15.06844    21.57709
SSEN    5.707     1.96225    0.57815     2.93462
SSUB    0.36507   0.07968    0           0.44985
SUB     1.0539    0          0           2.37103
T1      0         0          0           0.56024
T2      1.87901   0          0           3.00718
UT2     0         0          0           0.15787

我的 matrix1 是使用 reshape 包的 cast 函数创建的枢轴 table,包含许多零。每当矩阵中的值为零时,我都不想显示 'cellnote',因为这只会混淆热图。

然而,到目前为止,我还没有想出如何做到这一点,非常感谢您的任何建议。

谢谢!

对我来说,它只是创建一个新矩阵用 NA 替换零并将其作为参数传递给 cellnote

matrix2 <- as.matrix(matrix1)
matrix2[matrix2 == 0] <- NA

Re-running 代码使用 matrix2

heatmap.2(as.matrix(matrix1),cellnote=matrix2,
      notecol="black",margins =c(9,6),trace="none",density.info="none",
      col=my_palette,Rowv=NA,Colv=NA,dendrogram="none",scale="row")

给予

(顺便说一句,你没有给出 my_palette,所以我在这个例子中进行了讨论。)