gpt4 book ai didi

r - 在 R 中绘制 pheatmap 时如何重新排序簇叶(列)?

转载 作者:行者123 更新时间:2023-12-01 14:33:38 24 4
gpt4 key购买 nike

我正在绘制一组 15 个样本,分为 A、B、C 三组,热图将它们排序为 C、A、B。(我读过这是因为它在右侧绘制了集群具有最强的相似性)。我想对簇进行排序,以便簇的叶子被视为 A、B、C(因此重新组织簇分支的顺序。是否有可以帮助我执行此操作的函数?

我用过的代码:

library(pheatmap)

pheatmap(mat, annotation_col = anno,
color = colorRampPalette(c("blue", "white", "red"))(50), show_rownames = F)

Image output from code below

(cluster_cols=FALSE 根本不会对样本进行聚类,但这不是我想要的)

我也在另一个论坛上找到了这个,但我不确定如何更改功能代码以及它是否适合我:

clustering_callback callback function to modify the clustering. Is called with two parameters: original hclust object and the matrix used for clustering. Must return a hclust object.

最佳答案

您好,我不确定这是否对您有帮助,但是当您检查?pheatmap 并向下滚动到示例时,最后一段代码确实给出了该示例。

# Modify ordering of the clusters using clustering callback option
callback = function(hc, mat){
sv = svd(t(mat))$v[,1]
dend = reorder(as.dendrogram(hc), wts = sv)
as.hclust(dend)
}

pheatmap(test, clustering_callback = callback)

我在我的热图上试过了,之前定义的函数实际上按照我需要的方式对集群进行了排序。尽管我不得不承认(因为我是 R 的新手)我并不完全理解定义的 callback 函数的作用。

也许你也可以用dendsort写一个函数package据我所知,您可以用它重新排列树状图的分​​支。

关于r - 在 R 中绘制 pheatmap 时如何重新排序簇叶(列)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56869382/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com