how to put key values and legends at the bottom of the heatmap

Viewed 2175

Does anyone show me how to put the expression key index and the legend key to appear at the bottom of the heatmap using pheatmap? you can use the following code to generate the heatmap. Thank you so much!

test = matrix(rnorm(200), 20, 10)
test[1:10, seq(1, 10, 2)] = test[1:10, seq(1, 10, 2)] + 3
test[11:20, seq(2, 10, 2)] = test[11:20, seq(2, 10, 2)] + 2
test[15:20, seq(2, 10, 2)] = test[15:20, seq(2, 10, 2)] + 4
colnames(test) = paste("Test", 1:10, sep = "")
rownames(test) = paste("Gene", 1:20, sep = "")
annotation_col = data.frame(
  CellType = factor(rep(c("CT1", "CT2"), 5)), Time = c("A", "B", "C","D","E"))
rownames(annotation_col) = paste("Test",1:10, sep = "")
ann_colors = list(
    Time = c(A = "white", B= "firebrick", C= "#fdbb84",D = "#e34a33", E = "red"),
    CellType = c(CT1 = "#1B9E77", CT2 = "#D95F02")) 

library("pheatmap")
pheatmap(test, annotation_col = annotation_col, annotation_colors = ann_colors)
  
1 Answers

pheatmap doesn't appear to offer the ability to control the position of the legend.

The code the draws your heatmap can be found here https://github.com/raivokolde/pheatmap.

Check out the R/pheatmap-package.r file.

That legend seems to be pretty hard-coded, see # Legend position and draw_legend = function(color, breaks, legend, ...

Related