从 R 中的 pheatmap 中的非选定行名中删除 NA

Remove NAs from non-selected rownames in pheatmap in R

我有一组选定的基因,我想对其进行重命名。但是在绘制它们时,我也得到了未选中的 NA。 我怎样才能删除只绘制我选择的基因的 NA?

library(pheatmap)
set.seed(2020)
    mat = matrix(rnorm(200),20,10)
    rownames(mat) = paste0("g",1:20)
    rownames(mat)[rownames(mat) == "g2"] <- "abc"
    rownames(mat)[rownames(mat) == "g4"] <- "pqr"
    rownames(mat)[rownames(mat) == "g6"] <- "zzz"
    selected_genes <- c("abc","pqr", "zzz")
    obj = pheatmap(mat,cluster_rows = T, scale = 'row', show_rownames = T, labels_row = selected_genes)

我看到你也可以这样做:

labRow <- c(row.names(mat)[1], rep('', length(row.names(mat))-2)) # Selected row2 as example
pheatmap(mat,cluster_rows = T, scale = 'row', show_rownames = T, labels_row = labRow) 

由于您已经发现用非打印值填充 label_row 参数,看来您应该尝试过:

obj = pheatmap(mat,cluster_rows = T, scale = 'row', show_rownames = T, 
                           labels_row = c(selected_genes,rep("   ",17) ) )