text: user982: I want to convert my phylogeny into a dendrogram so I can use it with dendextend in R to produce a tanglegram. I have made some progress but I keep encountering errors, see below:
  library(ape)
  library(dendextend)
  
  Tree <- rtree(10, rooted=F)
  
  Tree <- read.tree(file="clipboard", text=NULL) 
  # test <- as.dendrogram(Tree) 
  ## Error in ape::as.hclust.phylo(object) : the tree is not ultrametric
  
  Tree.ultra <- chronos(Tree)  
  # test <- as.dendrogram(Tree.ultra) 
  ## Error in ape::as.hclust.phylo(object) : the tree is not rooted
  
  Tree.ultra$root.edge <- 0
  # test <- as.dendrogram(Tree.ultra) 
  ## Error in ape::as.hclust.phylo(object) : the tree is not binary
  
  This thread seems to be the closest to answering my issues but the workflow is different and Im not sure how to address this binary issue. I have tried using as.hclust, as.hclust.phylo and hclust. 
  
  user982: After searching high and low I have found an answer from this thread
  Workflow goes like:
  library(DECIPHER)
  dend1 <- ReadDendrogram(file="clipboard") 
  
  # Alternatively to load from existing environment 
  Tree$node.label <- NULL # Need to remove node labels
  dend1 <- ReadDendrogram(textConnection(write.tree(Tree))) 
  
  This object can then be used in the dendextend package and tanglegram function. 
  
  user939: For your example to work you should replace the rtree function with the rcoal function, see example below.
  library(ape)  
  library(dendextend)   
  Tree <- rtree(10, rooted=F)
  is.ultrametric(Tree) 
  [1] FALSE 
  is.binary.tree(Tree) 
  [1] TRUE
  
  Tree_rcoal <- rcoal(10, rooted=F) 
  is.ultrametric(Tree_rcoal) 
  [1] TRUE
  is.binary.tree(Tree_rcoal) 
  [1] TRUE
  
  Tree_rcoal2 <- rcoal(10, rooted=F)
  
  tanglegram(Tree_rcoal, Tree_rcoal2)
  
  To make use of a file in newick format, you can try to convert with the chronos function.
  s <- "owls(((Strix_aluco:4.2,Asio_otus:4.2):3.1,Athene_noctua:7.3):6.3,Tyto_alba:13.5);"
  cat(s, file = "ex.tre", sep = "\n")
  tree.owls <- read.tree("ex.tre")
  is.ultrametric(tree.owls)
  [1] FALSE
  dendrogram <- chronos(tree.owls)
  
  Setting initial dates...
  Fitting in progress... get a first set of estimates
           Penalised log-lik = -24.04992 
  Optimising rates... dates... -24.04992 
  Optimising rates... dates... -24.04908 
  
  Done.
  is.ultrametric(dendrogram)
  [1] TRUE
  
  
original_text: 982: <p>I want to convert my phylogeny into a dendrogram so I can use it with dendextend in R to produce a tanglegram. I have made some progress but I keep encountering errors, see below:</p>
  
  <pre><code>library(ape)
  library(dendextend)
  
  Tree &lt;- rtree(10, rooted=F)
  
  Tree &lt;- read.tree(file="clipboard", text=NULL) 
  # test &lt;- as.dendrogram(Tree) 
  ## Error in ape::as.hclust.phylo(object) : the tree is not ultrametric
  
  Tree.ultra &lt;- chronos(Tree)  
  # test &lt;- as.dendrogram(Tree.ultra) 
  ## Error in ape::as.hclust.phylo(object) : the tree is not rooted
  
  Tree.ultra$root.edge &lt;- 0
  # test &lt;- as.dendrogram(Tree.ultra) 
  ## Error in ape::as.hclust.phylo(object) : the tree is not binary
  </code></pre>
  
  <p>This <a href="https://www.biostars.org/p/4576/" rel="nofollow noreferrer">thread</a> seems to be the closest to answering my issues but the workflow is different and Im not sure how to address this binary issue. I have tried using as.hclust, as.hclust.phylo and hclust. </p>
   982: <p>After searching high and low I have found an answer from this <a href="https://stackoverflow.com/questions/7445684/how-to-convert-a-tree-to-a-dendrogram-in-r">thread</a></p>
  
  <p>Workflow goes like:</p>
  
  <pre><code>library(DECIPHER)
  dend1 &lt;- ReadDendrogram(file="clipboard") 
  
  # Alternatively to load from existing environment 
  Tree$node.label &lt;- NULL # Need to remove node labels
  dend1 &lt;- ReadDendrogram(textConnection(write.tree(Tree))) 
  </code></pre>
  
  <p>This object can then be used in the dendextend package and tanglegram function. </p>
   939: <p>For your example to work you should replace the <code>rtree</code> function with the <code>rcoal</code> function, see example below.</p>
  
  <pre><code>library(ape)  
  library(dendextend)   
  Tree &lt;- rtree(10, rooted=F)
  is.ultrametric(Tree) 
  [1] FALSE 
  is.binary.tree(Tree) 
  [1] TRUE
  
  Tree_rcoal &lt;- rcoal(10, rooted=F) 
  is.ultrametric(Tree_rcoal) 
  [1] TRUE
  is.binary.tree(Tree_rcoal) 
  [1] TRUE
  
  Tree_rcoal2 &lt;- rcoal(10, rooted=F)
  
  tanglegram(Tree_rcoal, Tree_rcoal2)
  </code></pre>
  
  <p>To make use of a file in newick format, you can try to convert with the <code>chronos</code> function.</p>
  
  <pre><code>s &lt;- "owls(((Strix_aluco:4.2,Asio_otus:4.2):3.1,Athene_noctua:7.3):6.3,Tyto_alba:13.5);"
  cat(s, file = "ex.tre", sep = "\n")
  tree.owls &lt;- read.tree("ex.tre")
  is.ultrametric(tree.owls)
  [1] FALSE
  dendrogram &lt;- chronos(tree.owls)
  
  Setting initial dates...
  Fitting in progress... get a first set of estimates
           Penalised log-lik = -24.04992 
  Optimising rates... dates... -24.04992 
  Optimising rates... dates... -24.04908 
  
  Done.
  is.ultrametric(dendrogram)
  [1] TRUE
  </code></pre>
  