[R] Hclust tree to Figtree w/ branch lengths

Julian Banchier moreke at luukku.com
Fri Jan 18 19:50:41 CET 2013


Hi,

I'm doing hierarchical clustering, and want to export my dendrogram to a
tree-viewing/editing software. I can do this by converting the data to
Newick format (hc2Newick in ctc package), but I can't get branch lengths to
show in the resulting phylogram. I figured it might help to convert my
hclust object into a phylo object (as.phylo in ape package), but the
following lines give me this "Error in UseMethod("as.phylo") : no applicable
method for 'as.phylo' applied to an object of class "character":

data = read.table("C:/path/data.txt")
d <- dist(data, method = "euclidean")
library(ape)
fit <- as.phylo(hclust(d, method="ward")
library(ctc)
write.table(as.phylo(hc2Newick(fit),
file="C:/path/output.txt",row.names=FALSE,col.names=FALSE))

Would anyone have an idea about how to make this work?

Thanks so much in advance!
Julian



--
View this message in context: http://r.789695.n4.nabble.com/Hclust-tree-to-Figtree-w-branch-lengths-tp4655990.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list