]> git.donarmstrong.com Git - ape.git/blob - man/bind.tree.Rd
ff8cafe8d1b95c0864680b6fc2deb8ee39418679
[ape.git] / man / bind.tree.Rd
1 \name{bind.tree}
2 \alias{bind.tree}
3 \title{Binds Trees}
4 \usage{
5 bind.tree(x, y, where = "root", position = 0, interactive = FALSE)
6 \method{+}{phylo}(x, y)
7 }
8 \arguments{
9   \item{x}{an object of class \code{"phylo"}.}
10   \item{y}{an object of class \code{"phylo"}.}
11   \item{where}{an integer giving the number of the node or tip of the
12     tree \code{x} where the tree \code{y} is binded (\code{"root"} is a
13     short-cut for the root).}
14   \item{position}{a numeric value giving the position from the tip or
15     node given by \code{node} where the tree \code{y} is binded;
16     negative values are ignored.}
17   \item{interactive}{if \code{TRUE} the user is asked to choose the tip
18     or node of \code{x} by clicking on the tree which must be plotted.}
19 }
20 \description{
21   This function binds together two phylogenetic trees to give a single
22   object of class \code{"phylo"}.
23 }
24 \details{
25   The argument \code{x} can be seen as the receptor tree, whereas
26   \code{y} is the donor tree. The root of \code{y} is then grafted on a
27   location of \code{x} specified by \code{where} and, possibly,
28   \code{position}. If \code{y} has a root edge, this is added as in
29   internal branch in the resulting tree.
30
31   \code{x + y} is a shortcut for:
32
33   \preformatted{
34     bind.tree(x, y, position = if (is.null(x$root.edge)) 0 else
35     x$root.edge)
36   }
37 }
38 \value{
39   an object of class \code{"phylo"}.
40 }
41 \author{Emmanuel Paradis}
42 \seealso{
43   \code{\link{drop.tip}}, \code{\link{root}}
44 }
45 \examples{
46 ### binds the two clades of bird orders
47 cat("((Struthioniformes:21.8,Tinamiformes:21.8):4.1,",
48     "((Craciformes:21.6,Galliformes:21.6):1.3,Anseriformes:22.9):3.0):2.1;",
49     file = "ex1.tre", sep = "\n")
50 cat("(Turniciformes:27.0,(Piciformes:26.3,((Galbuliformes:24.4,",
51     "((Bucerotiformes:20.8,Upupiformes:20.8):2.6,",
52     "(Trogoniformes:22.1,Coraciiformes:22.1):1.3):1.0):0.6,",
53     "(Coliiformes:24.5,(Cuculiformes:23.7,(Psittaciformes:23.1,",
54     "(((Apodiformes:21.3,Trochiliformes:21.3):0.6,",
55     "(Musophagiformes:20.4,Strigiformes:20.4):1.5):0.6,",
56     "((Columbiformes:20.8,(Gruiformes:20.1,Ciconiiformes:20.1):0.7):0.8,",
57     "Passeriformes:21.6):0.9):0.6):0.6):0.8):0.5):1.3):0.7):1.0;",
58     file = "ex2.tre", sep = "\n")
59 tree.bird1 <- read.tree("ex1.tre")
60 tree.bird2 <- read.tree("ex2.tre")
61 unlink(c("ex1.tre", "ex2.tre")) # clean-up
62 (birds <- tree.bird1 + tree.bird2)
63 layout(matrix(c(1, 2, 3, 3), 2, 2))
64 plot(tree.bird1)
65 plot(tree.bird2)
66 plot(birds)
67
68 ### examples with random trees
69 x <- rtree(4, tip.label = LETTERS[1:4])
70 y <- rtree(4, tip.label = LETTERS[5:8])
71 x <- makeNodeLabel(x, prefix = "x_")
72 y <- makeNodeLabel(y, prefix = "y_")
73 x$root.edge <- y$root.edge <- .2
74
75 z <- bind.tree(x, y, po=.2)
76 plot(y, show.node.label = TRUE, font = 1, root.edge = TRUE)
77 title("y")
78 plot(x, show.node.label = TRUE, font = 1, root.edge = TRUE)
79 title("x")
80 plot(z, show.node.label = TRUE, font = 1, root.edge = TRUE)
81 title("z <- bind.tree(x, y, po=.2)")
82
83 z <- bind.tree(x, y, 2, .1)
84 plot(y, show.node.label = TRUE, font = 1, root.edge = TRUE)
85 title("y")
86 plot(x, show.node.label = TRUE, font = 1, root.edge = TRUE)
87 title("x")
88 plot(z, show.node.label = TRUE, font = 1, root.edge = TRUE)
89 title("z <- bind.tree(x, y, 2, .1)")
90
91 x <- rtree(100)
92 y <- rtree(100)
93 x$root.edge <- y$root.edge <- .2
94 z <- x + y
95 plot(y, show.tip.label = FALSE, root.edge = TRUE); axisPhylo()
96 title("y")
97 plot(x, show.tip.label = FALSE, root.edge = TRUE); axisPhylo()
98 title("x")
99 plot(z, show.tip.label = FALSE, root.edge = TRUE); axisPhylo()
100 title("z <- x + y")
101 layout(1)
102 }
103 \keyword{manip}