【问题标题】:Swap branches in WGCNA eigengene dendrogramWGCNA 特征基因树状图中的交换分支
【发布时间】:2015-11-13 12:33:03
【问题描述】:

我正在绘制 WGCNA 包中 moduleeigengenes 的树状图,我想订购/交换分支。我使用plotEigengeneNetworks 函数来绘制它,但无法定义分支的顺序。我知道有用于修改树状图的dendextend 包,但这不适用于plotEigengeneNetworks 函数产生的输出。对于如何实现这一点的任何建议,我都会有所帮助。

例子:

library(WGCNA)
set.seed(123)

ME <- data.frame(replicate(15, sample(1:10, 11, rep=TRUE)))
ME[,c(1:11)] <- sapply(ME[, c(1:11)], as.numeric)    

plotEigengeneNetworks(ME, plotAdjacency = TRUE, setLabels = colnames(ME), plotDendrograms = TRUE, plotHeatmaps = FALSE)

【问题讨论】:

    标签: r hierarchical-clustering bioconductor dendrogram dendextend


    【解决方案1】:

    查看 plotEigengeneNetworks 的代码,你将无法使用它做你想做的事。但是,您可以做的是重现它创建集群的方式,然后使用the dendextend package 直接更新树状图(从 hclust 生成),方法如下:

    # we need to run all of this to get the relevant packages...
    source("http://bioconductor.org/biocLite.R")
    biocLite("S4Vectors")
    biocLite("IRanges")
    biocLite("GenomeInfoDb")
    biocLite("AnnotationDbi")
    biocLite("GO.db")
    
    biocLite("WGCNA")
    
    # what the author wanted:
    library(WGCNA)
    set.seed(123)
    
    ME <- data.frame(replicate(15, sample(1:10, 11, rep=TRUE)))
    ME[,c(1:11)] <- sapply(ME[, c(1:11)], as.numeric)    
    
    plotEigengeneNetworks(ME, plotAdjacency = TRUE, setLabels = colnames(ME), plotDendrograms = TRUE, plotHeatmaps = FALSE)
    
    # =================================
    # Reproduce the above plot:
    corME = cor(ME)
    disME = as.dist(1 - corME)
    clust = fastcluster::hclust(disME, method = "average") # you could also use stats::hclust just as well...
    plot(clust)
    
    
    # Now that we got what we wanted, let's move to dendrogram land
    dend <- as.dendrogram(clust)
    
    # get dendextend
    if(!require(dendextend)) install.packages("dendextend")
    library(dendextend)
    dend <- hang.dendrogram(dend)
    # plot(dend) # it now looks similar to the hclust plot
    # we can now rotate the labels:
    dend <- color_labels(dend)
    dend2 <- rotate(dend, order = sort(labels(dend)))
    par(mfrow = c(1,2))
    plot(dend, main = "Original dend plot")
    plot(dend2, main = "Dend plot after rotating the labels")
    #
    

    结果:

    【讨论】:

      猜你喜欢
      • 2017-09-17
      • 2012-10-18
      • 1970-01-01
      • 1970-01-01
      • 2019-09-08
      • 2019-08-12
      • 2023-01-15
      • 2013-06-16
      • 1970-01-01
      相关资源
      最近更新 更多