Is there a way to get pheatmap (in R) to not write over the existing row_names if I were to change fontface (ie. bold), fontsize (i.e. size = 20), and color (i.e. blue) of the rows?

By default, the color of the row or column text is black when making a pheatmap, but with a little tweaking, one can change the color of the text as I learned by this post: How to change color of rownames display in pheatmap; however, the code just writes over existing rownames. So, if you were to do anything aside from a color change (ex. increase font or change the fontface), then you see the issue - the rownames in black at the default font and fontface are still very visible in the background. Is there a way to not have the default font showing in the background?

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 =
data$regulation = rep(c("up", "down"), each = 8)
data$colors = ifelse(data$regulation == "up", "red", "blue")

p = pheatmap(data[, 1:16])
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 = 15, fontface = "bold")

Here is the graph:

Graph with over-written text

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 at all.

Source link