问题
I know how to group rows (genes) by annotation category using pheatmap, and I know how to perform Person's correlation clustering on the whole set of rows (genes), but what I would like to accomplish would be to perform clustering (and show independent dendrograms) on each category independently.
Is that even possible? Or am I forced to create a separate heat map for each category to do the clustering on a category basis?
Check my MWE below:
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
)
Which produces:
来源:https://stackoverflow.com/questions/41648293/r-pheatmap-perform-clustering-and-show-dendrograms-per-annotation-category