]> git.donarmstrong.com Git - ape.git/blob - man/as.phylo.Rd
some big fixes for ape 2.7-1
[ape.git] / man / as.phylo.Rd
1 \name{as.phylo}
2 \alias{as.phylo}
3 \alias{as.phylo.hclust}
4 \alias{as.phylo.phylog}
5 \alias{as.hclust.phylo}
6 \alias{old2new.phylo}
7 \alias{new2old.phylo}
8 \alias{as.network.phylo}
9 \alias{as.igraph}
10 \alias{as.igraph.phylo}
11 \title{Conversion Among Tree and Network Objects}
12 \description{
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).
17
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).
23
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
27   \pkg{network}.
28
29   \code{old2new.phylo} and \code{new2old.phylo} are utility functions
30   for converting between the old and new coding of the class
31   \code{"phylo"}.
32 }
33 \usage{
34 as.phylo(x, ...)
35 \method{as.phylo}{hclust}(x, ...)
36 \method{as.phylo}{phylog}(x, ...)
37 \method{as.hclust}{phylo}(x, ...)
38 old2new.phylo(phy)
39 new2old.phylo(phy)
40 \method{as.network}{phylo}(x, directed = is.rooted(x), ...)
41 as.igraph(x, ...)
42 \method{as.igraph}{phylo}(x, directed = is.rooted(x), use.labels = TRUE, ...)
43 }
44 \arguments{
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"}.}
54 }
55 \value{
56   An object of class \code{"hclust"}, \code{"phylo"}, \code{"network"},
57   or \code{"igraph"}.
58 }
59 \author{Emmanuel Paradis}
60 \seealso{
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}}
64 }
65 \examples{
66 data(bird.orders)
67 hc <- as.hclust(bird.orders)
68 tr <- as.phylo(hc)
69 identical(bird.orders, tr) # FALSE, but...
70 all.equal(bird.orders, tr) # ... TRUE
71
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)
76 plot(hc)
77 par(mar = c(8, 0, 0, 0)) # leave space for the labels
78 plot(dend)
79
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)
86 layout(matrix(1))
87
88 \dontrun{
89 ### convert into networks:
90 if (require(network)) {
91     x <- as.network(rtree(10))
92     print(x)
93     plot(x, vertex.cex = 1:4)
94     plot(x, displaylabels = TRUE)
95 }
96 tr <- rtree(5)
97 if (require(igraph)) {
98     print((x <- as.igraph(tr)))
99     plot(x)
100     print(as.igraph(tr, TRUE, FALSE))
101     print(as.igraph(tr, FALSE, FALSE))
102 }
103 }
104 }
105 \keyword{manip}