1
votes

I am using cophyloplot to create a tanglegram of two phylogenetic trees. The method works well with small trees but as the trees get larger the output image remains the same size and I can't find a way to expand it.

Below is the code for a small tree that works fine (basically same as example at: 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)

This what the small tree code produces:

enter image description here

But when I use larger trees, they become unreadable. For example using trees with 100 tips results in this: enter image description here

It is impossible to read the tip labels. How can I expand the rendering so it is readable?

2
p.s.: this is an r question, not a python question. I've fixed the tags on this question.Tal Galili

2 Answers

1
votes

The tanglegram function comes with many options to improve the output of the image you get (especially the arguments lab.cex and margin_inner). Probably the biggest factor though is external to tanglegram and is the size of your graphic device (via dev.new), so playing with the width and height there would probably solve most of the issue

Here is a simple self contained code that shows how to play with these options to get a nice output.

########
## 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)

enter image description here

0
votes

##I hope this code help for large tree

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()