【问题标题】:How can I create a large tanglegram in R that is readable and can be saved如何在 R 中创建一个可读且可以保存的大缠结图
【发布时间】:2021-03-01 00:15:07
【问题描述】:

我正在使用 cophyloplot 创建两个系统发育树的缠结图。该方法适用于小树,但随着树变大,输出图像的大小保持不变,我找不到扩展它的方法。

下面是一棵可以正常工作的小树的代码(与https://www.rdocumentation.org/packages/ape/versions/5.4-1/topics/cophyloplot 的示例基本相同):

library(ape)

#two random trees
TreeA <- rtree(10)
TreeB <- rtree(10)

#creation of the association matrix:
association <- cbind(TreeB$tip.label, TreeB$tip.label)

cophyloplot(TreeA, TreeB, assoc = association, length.line = 4, space = 28, gap = 3)

这是小树代码产生的:

但是当我使用更大的树时,它们变得不可读。例如,使用具有 100 个提示的树会导致:

无法读取提示标签。如何扩展渲染使其可读?

【问题讨论】:

  • ps:这是一个 r 问题,而不是 python 问题。我已经修复了这个问题的标签。

标签: r dendrogram phylogeny dendextend


【解决方案1】:

tanglegram 函数提供了许多选项来改进您获得的图像的输出(尤其是参数 lab.cex 和 margin_inner)。可能最大的因素是缠结图的外部因素,并且是图形设备的大小(通过 dev.new),因此使用宽度和高度可能会解决大部分问题

这是一个简单的自包含代码,展示了如何使用这些选项来获得良好的输出。

########
## Nice example of some colored trees
# see the coloring of common sub trees:
set.seed(23235)
ss <- sample(1:150, 100)
dend1 <- iris[ss, -5] %>%
  dist() %>%
  hclust("com") %>%
  as.dendrogram()
dend2 <- iris[ss, -5] %>%
  dist() %>%
  hclust("sin") %>%
  as.dendrogram()
dend12 <- dendlist(dend1, dend2)
# dend12 %>% untangle %>% tanglegram
dev.new(width=5, height=4)

dend12 %>% tanglegram(common_subtrees_color_branches = TRUE,
                      lab.cex = .5, margin_inner = 1.3)

【讨论】:

    【解决方案2】:

    ##我希望这段代码对大树有所帮助

    library(ape)
    library(phytools)
    library(dendextend)
    library(viridis)
    library(dplyr)
    library(phylogram)
    
    tree1 <- read.tree(file = "c1.raxml.bestTree")
    tree1 <- midpoint.root(tree1)
    tree2 <- read.tree(file = "c1_gubbins.raxml.bestTree")
    tree2 <- midpoint.root(tree2)
    tree1 <- compute.brlen(tree1)
    tree2 <- compute.brlen(tree2)
    tree1<- as.dendrogram(tree1)
    tree1
    tree2<- as.dendrogram(tree2)
    dndlist <- dendextend::dendlist(tree1, tree2)
    dendextend::tanglegram(dndlist, fast = TRUE, margin_inner = 1.8, lab.cex = 0.3, lwd = 
    0.5, edge.lwd = 0.5, type = "r")
    dev.copy(pdf, 'Discrete001.pdf', width = 10, height = 11)
    dev.off()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-24
      • 2019-06-19
      • 1970-01-01
      • 2018-07-23
      • 1970-01-01
      • 2017-01-24
      • 1970-01-01
      • 2016-03-17
      相关资源
      最近更新 更多