2

Ok I've got a pretty basic problem I'm sure but I'm just too novice at R to fix it. I'm creating a heatmap using pheatmap and would like to display the raw numbers in each cell but also use scaling on the rows. The is issue is when I use display_numbers = nrow(theatmap_data) it only shows the transformed scaled number not the raw values.

Here's the snipet

library(pheatmap)
t(heatmap_data) -> theatmap_data
  
pheatmap((theatmap_data),cluster_rows= FALSE, cluster_cols = FALSE,
           scale ="row", display_numbers = nrow(theatmap_data))
thelatemail
  • 91,185
  • 12
  • 128
  • 188
JeffNKC
  • 21
  • 2

1 Answers1

3

If you want to show the raw values inside the cells, you can use the following code:

library(pheatmap)

# Generate a simple matrix
set.seed(1234)
theatmap_data <- matrix(runif(24), ncol=4)
rownames(theatmap_data) <- paste0("G", 1:6)
colnames(theatmap_data) <- paste0("S", 1:4)

# Show the content of the matrix
print(theatmap_data)
#           S1          S2        S3         S4
# G1 0.1137034 0.009495756 0.2827336 0.18672279
# G2 0.6222994 0.232550506 0.9234335 0.23222591
# G3 0.6092747 0.666083758 0.2923158 0.31661245
# G4 0.6233794 0.514251141 0.8372956 0.30269337
# G5 0.8609154 0.693591292 0.2862233 0.15904600
# G6 0.6403106 0.544974836 0.2668208 0.03999592

# display_numbers = matrix of rounded row values
pheatmap((theatmap_data),cluster_rows= FALSE, cluster_cols = FALSE,
           scale ="row", display_numbers = round(theatmap_data,2))

enter image description here

Marco Sandri
  • 23,289
  • 7
  • 54
  • 58
  • Thank you! That worked great. I guess I don't understand why when I tried : display_numbers = nrow(theatmap_data) it only showed the scaled numbers. But with display_numbers = round(theatmap_data,2) is shows the unscaled data. I have a lot to learn still. – JeffNKC Dec 22 '21 at 02:11
  • @JeffNKC Hi Jeff. From the help of pheatmap: `display_numbers: If this is a matrix (with same dimensions as original matrix), the contents of the matrix are shown instead of original values.` Please, accept and upvote my answer if you find it useful. – Marco Sandri Dec 22 '21 at 14:59