title: How to convert a tree to a dendrogram in R?
body: <p>How can I convert a tree (which is the output of my Java program) to a dendrogram in R? </p>
  
  <p>Currently, I am converting the tree into the Newick format, using the suggestion given <a href="https://stackoverflow.com/questions/2612579/converting-a-tree-to-newick-format-java">here</a>. And then I use the <code>ape</code> package in R to read the Newick-formatted tree:</p>
  
  <pre><code>library("ape")
  cPhylo &lt;- read.tree(file = "gc.tree")
  </code></pre>
  
  <p>Finally I use <code>as.hclust</code> in R to convert the tree into a dendrogram:</p>
  
  <pre><code>dendrogram &lt;- as.hclust(gcPhylo)
  </code></pre>
  
  <p>However, the dendrogram requires the branch lengths. Although I insert the branch lengths, I am getting an error saying that the tree is not ultrametric:</p>
  
  <blockquote>
    <p>Error in as.hclust.phylo(gcPhylo) : the tree is not ultrametric</p>
  </blockquote>
  
  <p>I guess I am doing something wrong while inserting the branch lengths.</p>
  
  <p>Is there any other way that I can follow? Or how can I insert the branch lengths while converting the tree into the Newick format? Equal branch lengths would be fine.</p>