3 \alias{as.phylo.hclust}
4 \alias{as.phylo.phylog}
5 \alias{as.hclust.phylo}
8 \alias{as.network.phylo}
10 \alias{as.igraph.phylo}
11 \title{Conversion Among Tree and Network Objects}
13 \code{as.phylo} is a generic function which converts an object into a
14 tree of class \code{"phylo"}. There are currently two methods for
15 objects of class \code{"hclust"} and of class \code{"phylog"}
16 (implemented in the package ade4).
18 \code{as.hclust.phylo} is a method of the generic
19 \code{\link[stats]{as.hclust}} which converts an object of class
20 \code{"phylo"} into one of class \code{"hclust"}. This can used to
21 convert an object of class \code{"phylo"} into one of class
22 \code{"dendrogram"} (see examples).
24 \code{as.network} and \code{as.igraph} convert trees of class
25 \code{"phylo"} into these respective classes defined in the packages
26 of the same names. Note that the generic of the former is defined in
29 \code{old2new.phylo} and \code{new2old.phylo} are utility functions
30 for converting between the old and new coding of the class
35 \method{as.phylo}{hclust}(x, ...)
36 \method{as.phylo}{phylog}(x, ...)
37 \method{as.hclust}{phylo}(x, ...)
40 \method{as.network}{phylo}(x, directed = is.rooted(x), ...)
42 \method{as.igraph}{phylo}(x, directed = is.rooted(x), use.labels = TRUE, ...)
45 \item{x}{an object to be converted into another class.}
46 \item{directed}{a logical value: should the network be directed? By
47 default, this depends on whether the tree is rooted or not.}
48 \item{use.labels}{a logical specifying whether to use labels to build
49 the network of class \code{"igraph"}. If \code{TRUE} and the tree
50 has no node labels, then some default labels are created first. If
51 \code{FALSE}, the network is built with integers.}
52 \item{\dots}{further arguments to be passed to or from other methods.}
53 \item{phy}{an object of class \code{"phylo"}.}
56 An object of class \code{"hclust"}, \code{"phylo"}, \code{"network"},
60 In an object of class \code{"hclust"}, the \code{height} gives the
61 distance between the two sets that are being agglomerated. So these
62 distances are divided by two when setting the branch lengths of a
65 \author{Emmanuel Paradis}
67 \code{\link[stats]{hclust}}, \code{\link[stats]{as.hclust}},
68 \code{\link[stats]{dendrogram}}, \code{\link[ade4]{phylog}},
69 \code{\link{as.phylo.formula}}
73 hc <- as.hclust(bird.orders)
75 identical(bird.orders, tr) # FALSE, but...
76 all.equal(bird.orders, tr) # ... TRUE
78 ### shows the three plots for tree objects:
79 dend <- as.dendrogram(hc)
80 layout(matrix(c(1:3, 3), 2, 2))
81 plot(bird.orders, font = 1)
83 par(mar = c(8, 0, 0, 0)) # leave space for the labels
86 ### how to get (nearly) identical plots with
87 ### plot.phylo and plot.dendrogram:
88 layout(matrix(1:2, 2, 1))
89 plot(bird.orders, font = 1, no.margin = TRUE)
90 par(mar = c(0, 0, 0, 8))
91 plot(dend, horiz = TRUE)
95 ### convert into networks:
96 if (require(network)) {
97 x <- as.network(rtree(10))
99 plot(x, vertex.cex = 1:4)
100 plot(x, displaylabels = TRUE)
103 if (require(igraph)) {
104 print((x <- as.igraph(tr)))
106 print(as.igraph(tr, TRUE, FALSE))
107 print(as.igraph(tr, FALSE, FALSE))