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"},
59 \author{Emmanuel Paradis}
61 \code{\link[stats]{hclust}}, \code{\link[stats]{as.hclust}},
62 \code{\link[stats]{dendrogram}}, \code{\link[ade4]{phylog}},
63 \code{\link{as.phylo.formula}}
67 hc <- as.hclust(bird.orders)
69 identical(bird.orders, tr) # FALSE, but...
70 all.equal(bird.orders, tr) # ... TRUE
72 ### shows the three plots for tree objects:
73 dend <- as.dendrogram(hc)
74 layout(matrix(c(1:3, 3), 2, 2))
75 plot(bird.orders, font = 1)
77 par(mar = c(8, 0, 0, 0)) # leave space for the labels
80 ### how to get (nearly) identical plots with
81 ### plot.phylo and plot.dendrogram:
82 layout(matrix(1:2, 2, 1))
83 plot(bird.orders, font = 1, no.margin = TRUE)
84 par(mar = c(0, 0, 0, 8))
85 plot(dend, horiz = TRUE)
89 ### convert into networks:
90 if (require(network)) {
91 x <- as.network(rtree(10))
93 plot(x, vertex.cex = 1:4)
94 plot(x, displaylabels = TRUE)
97 if (require(igraph)) {
98 print((x <- as.igraph(tr)))
100 print(as.igraph(tr, TRUE, FALSE))
101 print(as.igraph(tr, FALSE, FALSE))