【问题标题】:Pheatmap: Re-order leaves in dendogramPheatmap:在树状图中重新排序叶子
【发布时间】:2019-02-19 09:07:16
【问题描述】:

我使用 pheatmap 包基于层次聚类创建了一个带有相应树状图的热图。现在,我想更改树状图中叶子的顺序。最好使用最佳叶子方法。我已经四处搜索,但没有找到任何关于如何改变实现这一点的解决方案。

我会很感激有关如何使用最佳叶子方法更改叶子顺序的建议。

这是我的随机数据示例代码:

mat <- matrix(rgamma(1000, shape = 1) * 5, ncol = 50)
p <- pheatmap(mat, 
         clustering_distance_cols = "manhattan",
         cluster_cols=TRUE,
         cluster_rows=FALSE
         )

【问题讨论】:

    标签: r pheatmap


    【解决方案1】:

    对于“最佳叶子排序”,您可以使用 seriation 库中的 order 方法。 pheatmap 接受 clustering_callback 参数。根据文档:

    clustering_callback 回调函数来修改集群。使用两个参数调用:原始 hclust 对象和使用的矩阵 用于聚类。必须返回一个 hclust 对象。

    所以你需要构造一个回调函数,它接受hclust对象和初始矩阵并返回优化的hclust对象。

    这是一个代码:

    library(pheatmap)
    library(seriation)
    
    cl_cb <- function(hcl, mat){
        # Recalculate manhattan distances for reorder method
        dists <- dist(mat, method = "manhattan")
    
        # Perform reordering according to OLO method
        hclust_olo <- reorder(hcl, dists)
        return(hclust_olo)
    }
    
    mat <- matrix(rgamma(1000, shape = 1) * 5, ncol = 50)
    p <- pheatmap(mat, 
             clustering_distance_cols = "manhattan",
             cluster_cols=TRUE,
             cluster_rows=FALSE,
             clustering_callback = cl_cb
             )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-16
      • 1970-01-01
      • 1970-01-01
      • 2011-06-10
      • 2014-01-16
      • 2018-08-30
      • 1970-01-01
      • 2013-06-18
      相关资源
      最近更新 更多