我知道如何使用pheatmap按注释类别对行(基因)进行分组,我知道如何在整个行集(基因)上执行Person的相关聚类,但我想要实现的是独立地对每个类别执行聚类(并显示独立的树形图)。
这甚至可能吗?或者我是否被迫为每个类别创建一个单独的热图,以便在类别的基础上进行聚类?
检查下面的MWE:
set.seed(1)
library(pheatmap)
mymat <- matrix(rexp(600, rate=.1), ncol=12)
colnames(mymat) <- c(rep("treatment_1", 3), rep("treatment_2", 3), rep("treatment_3", 3), rep("treatment_4", 3))
rownames(mymat) <- paste("gene", 1:dim(mymat)[1], sep="_")
annotdf <- data.frame(row.names = paste("gene", 1:dim(mymat)[1], sep="_"), category = c(rep("CATEGORY_1", 10), rep("CATEGORY_2", 10), rep("CATEGORY_3", 10), rep("CATEGORY_4", 10), rep("CATEGORY_5", 10)))
pheatmap(mymat,
scale="row",
cluster_rows = FALSE,
cluster_cols = FALSE,
gaps_row=c(10,20,30,40),
gaps_col=c(3,6,9),
cellheight = 6,
cellwidth = 20,
border_color=NA,
fontsize_row = 6,
filename = "TEST1.png",
annotation_row = annotdf
)
pheatmap(mymat,
scale="row",
cluster_rows = TRUE,
cluster_cols = FALSE,
clustering_distance_rows = "correlation",#Pearson's
clustering_method = "average",
gaps_col=c(3,6,9),
cellheight = 6,
cellwidth = 20,
border_color=NA,
fontsize_row = 6,
filename = "TEST2.png",
annotation_row = annotdf
)
产生: