Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a tree to a dendrogram in R?

Tags:

r

tree

dendrogram

How can I convert a tree (which is the output of my Java program) to a dendrogram in R?

Currently, I am converting the tree into the Newick format, using the suggestion given here. And then I use the ape package in R to read the Newick-formatted tree:

library("ape")
cPhylo <- read.tree(file = "gc.tree")

Finally I use as.hclust in R to convert the tree into a dendrogram:

dendrogram <- as.hclust(gcPhylo)

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:

Error in as.hclust.phylo(gcPhylo) : the tree is not ultrametric

I guess I am doing something wrong while inserting the branch lengths.

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.

like image 547
Burcu Avatar asked Sep 16 '11 13:09

Burcu


2 Answers

This is an old question, but it has inadequate answers so far. Since I had the same problem, and my googlefoo was having problems finding the answer, here you go:

library("ape")
cPhylo <- read.tree(file = "gc.tree")
dendrogram <- chronos(cPhylo)
like image 175
Sandain Avatar answered Oct 13 '22 06:10

Sandain


This is an old question, but all of the previous answers require the tree to be made ultrametric before being converted to a dendrogram object.

You can use the DECIPHER package to read a dendrogram object from a Newick formatted file:

dend <- ReadDendrogram(path_to_newick_file)
like image 23
Erik Wright Avatar answered Oct 13 '22 06:10

Erik Wright