首页 > 解决方案 > 显示复杂热图中的数字

问题描述

嗨,我正在尝试在 HEATMAP 上显示 df 的数字

我有这个 df

> matrinrmatr
      ce   n1   n2   n3   ca
sn  6.47 1.89 0.52   NA   NA
inn 6.47 3.94   NA   NA   NA
pn  6.93   NA   NA   NA   NA
bn  6.40 6.63 5.08 5.56 2.73
cn  7.67 2.13 2.03 5.70   NA
vn  7.29 3.37 2.76 3.74 2.18
cin 5.57 3.61 2.51 3.72 2.18

我尝试使用以下脚本制作热图

hmmatrinr <- Heatmap(matrinrmatr, 
                     row_title="Grupos", 
                     column_title="camadas", 
                     col=colheatp, 
                     cluster_rows=FALSE, 
                     cluster_columns=FALSE, 
                     show_column_dend=FALSE, 
                     width=unit(6, "cm"), 
                     height=unit(9, "cm"), 
                     heatmap_legend_param=list(
                       title="Score", 
                       at=c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), 
                       legend_height=unit(8, "cm"), 
                       grid_width=unit(0.5, "cm")
                     ), 
                     layer_fun <- function(j, i, x, y, width, height, fill) {
                       grid.text
                       (sprintf("%s", 
                                pindex(matrinrmatr, i, j), 
                                x=x, y=y, 
                                gp=gpar(fontsize=10, col="grey")))
                     }
)

我有这个没有 layer_fun 部分的热图,没有单元格上的数字 https://i.stack.imgur.com/0AMoV.png

问题出在 layer_fun 部分

它给了我

Error in sprintf("%s", pindex(matrinrmatr, i, j), x = x, y = y, gp = gpar(fontsize = 10,  : 
  arguments cannot be recycled to the same length

我试着用

layer_fun <- function(j, i, x, y, width, height, fill) {
  grid.text
  (sprintf(
    "%f", 
    pindex(matrinrmatr, i, j), x=x, y=y))
}

结果是

 Warning message:
    In sprintf("%f", pindex(matrinrmatr, i, j), x = x, y = y) :
      2 arguments not used by format '%f

也试过

layer_fun <- function(j, i, x, y, width, height, fill) {
  grid.text
  (sprintf("%s", 
           pindex(matrinrmatr, i, j), x=x, y=y))
}

并给了我

Warning message:
In sprintf("%s", pindex(matrinrmatr, i, j), x = x, y = y) :
  2 arguments not used by format '%s'

没有数字

如果有人可以帮助我,我将不胜感激。谢谢

标签: rheatmapcomplexheatmap

解决方案


推荐阅读