在 R 中结合作弊图

Combining pheatmaps in R

我一直在解决如何将 2 个或更多 pheatmaps(热图)组合成最终情节的问题,但没有成功。

data1 <- structure(list(DC1 = c(NA, NA, 1.98), DC2 = c(NA, NA, 0.14), 
    DC3 = c(1.85, 1.51, 0.52), DC4 = c(0.89, 0.7, 1.47), DC5 = c(0, 
    0.78, 0), DC6 = c(0, 1.3, 0), DC7 = c(0, 1.47, 0), DC8 = c(0, 
    1.2, 0), DC9 = c(0, 0, 0), DC10 = c(0.51, 1.9, 0)), .Names = c("DC1", 
    "DC2", "DC3", "DC4", "DC5", "DC6", "DC7", "DC8", "DC9", "DC10"), 
    enter code here`class = "data.frame", row.names = c("A", "B",  "C"))

data 2 <- structure(list(DC1 = c(9.56, 1.87, 2.07, 1.87, 2.07, 1.35), DC2 = c(5.51, 1.13, 1.25, 1.13, 0.99, 0.45), DC3 = c(4.84, 1.17, 0.66, 1.17, 
0.34, 0.16), DC4 = c(4.18, 0.59, 0.05, 0.97, 0.43, 0.59), DC5 = c(3.26, 
0, 0.14, 0.31, 0.79, 0.63), DC6 = c(3.35, 0, 1.12, 0.05, 1.12, 
0), DC7 = c(4.18, 0.63, 1.27, 0.47, 1.27, 0), DC8 = c(4.37, 1.17, 
1.3, 1.17, 0, 0), DC9 = c(4.3, 1.13, 0, 1.13, 0, 0), DC10 = c(7.47, 
1.88, 0.71, 1.88, 0, 0)), .Names = c("DC1", "DC2", "DC3", "DC4", 
"DC5", "DC6", "DC7", "DC8", "DC9", "DC10"), class = "data.frame", row.names = c("TD6 vs SH", 
"TD6 vs SAP", "TD6 vs NEA", "SH vs SAP", "SH vs NEA", "SAP vs NEA"
))

我使用 pheatmap 通过使用以下两个代码非常轻松地构建了一个热图:

hm_data1 <- pheatmap(as.matrix(data1))
hm_data2 <- pheatmap(as.matrix(data2))

但是,我无法将两者都打印在一张图中。我想水平地看到它们。但是,我的真实图形将由 16 个 pheatmap 组成,因此它们必须排列成 4 列和 4 行。

我试过 par mfrow 但没有成功。

如何合并作弊图?

我知道有很多 R 包可以绘制热图,但我想用 pheatmap

这会起作用。

library(gridExtra); library(pheatmap)

m <- matrix(c(1:4), ncol=2)
n <- matrix(c(1,1,1,2), ncol=2)
a <- list(pheatmap(m)[[4]])
a[[2]] <- pheatmap(n)[[4]]
z <- do.call(grid.arrange,a)
plot(z)

基于其中一条评论。如果你有很多单一的地块;你可以使用这样的循环。

mn <- list(m, n)

a <- list()
for(i in 1:length(mn)){
  a[i] <- list(pheatmap(mn[[i]])[[4]])
}

z <- do.call(grid.arrange,a)
plot(z)

重点是将单个地块的所有数据添加到列表中。然后您可以遍历列表,应用 pheatmap.