我使用下面的代码在R中获取ComplexHeatmap。我尝试了两种不同的方法,在代码的注解中指定。两者之间唯一的区别是,在第一种情况下,我依靠ComplexHeatmap来进行聚类,而在第二种情况下,我自己进行聚类,并将hclust对象传递给Heatmap。从理论上讲,我应该得到相同的数据聚类,但我没有。我不知道我误解了什么。我知道热图不应该是相同的,但我相信样本的聚类应该是相同的。我已经在this Github上分享了这方面的数据。PS:聚类相似(但以相反的顺序显示),但不完全相同。
lung = read.csv("all_lung.csv")
lung["subtype_grouped_meso"] = lung["subtype"]
lung[lung["subtype"] == "Not.Otherwise.Specified" | lung["subtype"] ==
"Epithelioid" | lung["subtype"] == "Sarcomatoid" |
lung["subtype"] == "Biphasic",
"subtype_grouped_meso"] = "meso"
subtype = lung[["subtype_grouped_meso"]]
rownames(lung) = lung[["X"]]
lung = lung[, chr_keep]
subtype_colors <- c(
"Adeno" = "red",
"Squamous" = "green",
"SCLC" = "blue",
"meso" = "orange"
)
lung = t(lung)
column_ha <- HeatmapAnnotation(subtype = subtype,
counts = log10(colSums(lung)),
col = list(subtype =
subtype_colors))
# Method 1
Heatmap(lung,
top_annotation = column_ha,
clustering_distance_columns = "pearson",
clustering_method_columns = "ward.D",
cluster_rows = F,
show_column_names = F,
show_row_names = F,
show_row_dend = F)
# Method 2 (manually do the clustering)
cor_matrix <- cor(lung, method = "pearson")
cor_distance <- as.dist(1 - cor_matrix)
hc <- hclust(cor_distance, method = "ward.D")
Heatmap(cor_matrix,
top_annotation = column_ha,
name = "correlation",
cluster_columns = hc,
cluster_rows = hc,
show_column_names = F,
show_row_names = F,
show_row_dend = F,
col = colorRamp2(c(-1, 0, 1), c("blue", "white", "red")))
1条答案
按热度按时间mccptt671#
类似的问题here
stats
包中的reorder.dendogram
函数最好地描述了这一点:树状图有许多不同的顺序与所施加的结构一致。该函数接受一个树状图和一个值向量,并按照提供的向量的顺序对树状图进行重新排序,同时保持树状图上的约束。