1

I am plotting heatmap by pheatmap package in r.

I applied the display_numbers function to display the values in a matrix into the heatmap, and I got:

heatmap

I got so many NA in my matrix and I would like to hide them in the heatmap, how can I do that?

  • 1
    Hi @leeleelee please consider editing your question to include sample code, sample data and expected output. You could use `dput(head(mysampledata,20))` to add sample data to your question. – NelsonGon Dec 25 '18 at 14:25

1 Answers1

2

First off, it is a lot easier for people to help you if you were to provide reproducible and minimal sample data. Please consider reviewing how to provide a minimal reproducible example/attempt for future posts.


As to your question:

  1. Let's generate some sampe data

    set.seed(2018)
    mat <- matrix(runif(20), 4, 5)
    

    We use a second matrix to display values via the argument display_numbers of pheatmap. Here we simply copy the original matrix and randomly generate some NA values:

    mat2 <- mat
    mat2[mat2 < 0.5] <- NA
    
  2. We now replace NA values with empty strings.

    mat2[is.na(mat2)] <- ""
    
  3. Let's show the heatmap

    pheatmap(mat, display_numbers = mat2)
    

enter image description here

Maurits Evers
  • 49,617
  • 4
  • 47
  • 68
  • 1
    Thanks for all the advice, I will do my best to ask a good question next time. –  Dec 26 '18 at 00:50