R pheathmap,如何在两个热图图像中设置相同的比例?

时间:2016-10-24 19:42:17

标签: r ggplot2 heatmap pheatmap

我在两个不同的csv文件中有两个矩阵,我想绘制它们具有相同的色阶。

这就是我现在所拥有的并且它无法正常工作:

enter image description here

正如您所看到的,两个图像使用相同的颜色范围(从蓝色到红色),但它们的含义不同:它们具有不同的间隔。

我想将相同的颜色关联到两个热图中的相同值范围。

这是我的热图代码:

library(pheatmap)
datatable_normal = data.matrix(read.table(fileName, sep="\t", header=T, row.names=1))
pheatmap(datatable_normal, cluster_rows=FALSE, cluster_cols=FALSE, show_rownames=T, width=10, height=10)

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

您可以通过提供相同的breaks来设置相同的比例。

以下是我的例子:

library(pheatmap)

  ## example data   
set.seed(1); test1 <- matrix(rnorm(25, 0, 10), 5, 5)
set.seed(2); test2 <- matrix(rnorm(25, 30, 10), 5, 5)
colnames(test1) = paste0("Test", 1:5); rownames(test1) = paste0("Gene", 1:5)
colnames(test2) = paste0("Test", 1:5); rownames(test2) = paste0("Gene", 1:5)

  ## make breaks from combined range
Breaks <- seq(min(c(test1, test2)), max(c(test1, test2)), length = 100)

  ## draw   
pheatmap(test1, breaks = Breaks, cluster_rows=FALSE, cluster_cols=FALSE)
pheatmap(test2, breaks = Breaks, cluster_rows=FALSE, cluster_cols=FALSE)

enter image description here enter image description here