0

Is there a way to get pheatmap (in R) to not write over the row_names with new, colored text, if I change the color of the text? By default, the color of the row or column text is black, but with a little tweaking, one can change the color of the text as I learned by this post: pheatmap: change text color. However, it just writes over the black text with a new color, which is problematic when there are quite a few rows. Also, if one wants to change the fontface to bold or the size of the font, the issue is really noticeable.

Here is a reproducible example:

library(pheatmap) ; library(grid)
data <- replicate(16, rnorm(16))
rownames(data) <- paste0("OTU", c(1:nrow(data)))
colnames(data) <- paste("Sample", c(1:ncol(data)))
data = as.data.frame(data)
data$regulation = rep(c("up", "down"), each = 8)
data$colors = ifelse(data$regulation == "up", "green", "red")

#Graphing
p = pheatmap(data[, 1:15])
cols = data[order(match(rownames(data), p$gtable$grobs[[5]]$label)), ]$colors  #Assuming row labels are in grob 5
p$gtable$grobs[[5]]$gp = gpar(col = cols, fontsize = 20, fontface = "bold")
p

Here is the resulting graph:

pheatmap: rows being overwritten

Is there a way to avoid the original text to be written (as seen in the background)? In attempts to do so, I've set the show_rownames = FALSE and all this does is over ride the code and no rownames are written.

Purrsia
  • 712
  • 5
  • 18

0 Answers0