简体   繁体   中英

Remove NAs from non-selected rownames in pheatmap in R

I have a selected group of genes I would like to plot which I have renamed. But when plotting them I also get the NAs for the non-selected. How could I remove the NAs only plotting my selected genes?

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)

在此处输入图像描述

I have seen you can also do something like:

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) 

在此处输入图像描述

Since you already discovered that padding the label_row parameter with non-printing values, it seems you should have tried:

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

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM