JeffNKC
JeffNKC

Reputation: 21

Showing raw numbers in cells of pheatmap in R

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

Upvotes: 2

Views: 3014

Answers (1)

Marco Sandri
Marco Sandri

Reputation: 24262

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

Upvotes: 5

Related Questions