如何将键值和图例放在热图的底部

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

有人告诉我如何使用 pheatmap 将表达式键索引和图例键显示在热图的底部吗?您可以使用以下代码生成热图。 非常感谢!

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)
  

pheatmap 似乎没有提供控制图例位置的能力。

可以在此处找到绘制热图的代码 https://github.com/raivokolde/pheatmap

检查 R/pheatmap-package.r 文件。

那个传说好像还不错hard-coded,见# Legend positiondraw_legend = function(color, breaks, legend, ...