0

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)

enter image description here

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) 

enter image description here

aynber
  • 22,380
  • 8
  • 50
  • 63
Ecg
  • 908
  • 1
  • 10
  • 28

1 Answers1

1

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) ) ) 

enter image description here

IRTFM
  • 258,963
  • 21
  • 364
  • 487