]> git.donarmstrong.com Git - ape.git/blob - man/plot.phylo.Rd
change nlm to nlminb in ace() + new makeNodeLabel + fixed drop.tip
[ape.git] / man / plot.phylo.Rd
1 \name{plot.phylo}
2 \alias{plot.phylo}
3 \alias{plot.multiPhylo}
4 \title{Plot Phylogenies}
5 \usage{
6 \method{plot}{phylo}(x, type = "phylogram", use.edge.length = TRUE,
7     node.pos = NULL, show.tip.label = TRUE, show.node.label = FALSE,
8     edge.color = "black", edge.width = 1, font = 3,
9     cex = par("cex"), adj = NULL, srt = 0, no.margin = FALSE,
10     root.edge = FALSE, label.offset = 0, underscore = FALSE,
11     x.lim = NULL, y.lim = NULL, direction = "rightwards",
12     lab4ut = "horizontal", tip.color = "black", ...)
13 \method{plot}{multiPhylo}(x, layout = 1, ...)
14 }
15 \arguments{
16   \item{x}{an object of class \code{"phylo"} or of class
17     \code{"multiPhylo"}.}
18   \item{type}{a character string specifying the type of phylogeny to be
19     drawn; it must be one of "phylogram" (the default), "cladogram",
20     "fan", "unrooted", "radial" or any unambiguous abbreviation of
21     these.}
22   \item{use.edge.length}{a logical indicating whether to use the edge
23     lengths of the phylogeny to draw the branches (the default) or not
24     (if \code{FALSE}). This option has no effect if the object of class
25     \code{"phylo"} has no `edge.length' element.}
26   \item{node.pos}{a numeric taking the value 1 or 2 which specifies the
27     vertical position of the nodes with respect to their descendants. If
28     \code{NULL} (the default), then the value is determined in relation
29     to `type' and `use.edge.length' (see details).}
30   \item{show.tip.label}{a logical indicating whether to show the tip
31     labels on the phylogeny (defaults to \code{TRUE}, i.e. the labels
32     are shown).}
33   \item{show.node.label}{a logical indicating whether to show the node
34     labels on the phylogeny (defaults to \code{FALSE}, i.e. the labels
35     are not shown).}
36   \item{edge.color}{a vector of mode character giving the colours used
37     to draw the branches of the plotted phylogeny. These are taken to be
38     in the same order than the component \code{edge} of \code{phy}. If
39     fewer colours are given than the length of \code{edge}, then the
40     colours are recycled.}
41   \item{edge.width}{a numeric vector giving the width of the branches of
42     the plotted phylogeny. These are taken to be in the same order than
43     the component \code{edge} of \code{phy}. If fewer widths are given
44     than the length of \code{edge}, then these are recycled.}
45   \item{font}{an integer specifying the type of font for the labels: 1
46     (plain text), 2 (bold), 3 (italic, the default), or 4 (bold
47     italic).}
48   \item{cex}{a numeric value giving the factor scaling of the tip and
49     node labels (Character EXpansion). The default is to take the
50     current value from the graphical parameters.}
51   \item{adj}{a numeric specifying the justification of the text strings
52     of the labels: 0 (left-justification), 0.5 (centering), or 1
53     (right-justification). This option has no effect if \code{type =
54       "unrooted"}. If \code{NULL} (the default) the value is set with
55     respect of \code{direction} (see details).}
56   \item{srt}{a numeric giving how much the labels are rotated in degrees
57     (negative values are allowed resulting in clock-like rotation); the
58     value has an effect respectively to the value of
59     \code{direction} (see Examples). This option has no effect if
60     \code{type = "unrooted"}.}
61   \item{no.margin}{a logical. If \code{TRUE}, the margins are set to
62     zero and the plot uses all the space of the device (note that this
63     was the behaviour of \code{plot.phylo} up to version 0.2-1 of `ape'
64     with no way to modify it by the user, at least easily).}
65   \item{root.edge}{a logical indicating whether to draw the root edge
66     (defaults to FALSE); this has no effect if `use.edge.length = FALSE'
67     or if `type = "unrooted"'.}
68   \item{label.offset}{a numeric giving the space between the nodes and
69     the tips of the phylogeny and their corresponding labels. This
70     option has no effect if \code{type = "unrooted"}.}
71   \item{underscore}{a logical specifying whether the underscores in tip
72     labels should be written as spaces (the default) or left as are (if
73     \code{TRUE}).}
74   \item{x.lim}{a numeric vector of length one or two giving the limit(s)
75     of the x-axis. If \code{NULL}, this is computed with respect to
76     various parameters such as the string lengths of the labels and the
77     branch lengths. If a single value is given, this is taken as the
78     upper limit.}
79   \item{y.lim}{same than above for the y-axis.}
80   \item{direction}{a character string specifying the direction of the
81     tree. Four values are possible: "rightwards" (the default),
82     "leftwards", "upwards", and "downwards".}
83   \item{lab4ut}{(= labels for unrooted trees) a character string
84     specifying the display of tip labels for unrooted trees: either
85     \code{"horizontal"} where all labels are horizontal (the default),
86     or \code{"axial"} where the labels are displayed in the axis of the
87     corresponding terminal branches. This option has an effect only if
88     \code{type = "unrooted"}.}
89   \item{tip.color}{the colours used for the tip labels, eventually
90     recycled (see examples).}
91   \item{layout}{the number of trees to be plotted simultaneously.}
92   \item{...}{further arguments to be passed to \code{plot} or to
93     \code{plot.phylo}.}
94 }
95 \description{
96   These functions plot phylogenetic trees on the current graphical
97   device.
98 }
99 \details{
100   If \code{x} is a list of trees (i.e., an object of class
101   \code{"multiPhylo"}), then any further argument may be passed with
102   \code{...} and could be any one of those listed above for a single
103   tree.
104
105   The font format of the labels of the nodes and the tips is the same.
106
107   If \code{no.margin = TRUE}, the margins are set to zero and are not
108   restored after plotting the tree, so that the user can access the
109   coordinates system of the plot.
110
111   The option `node.pos' allows the user to alter the vertical position
112   (i.e. ordinates) of the nodes. If \code{node.pos = 1}, then the
113   ordinate of a node is the mean of the ordinates of its direct
114   descendants (nodes and/or tips). If \code{node.pos = 2}, then the
115   ordinate of a node is the mean of the ordinates of all the tips of
116   which it is the ancestor. If \code{node.pos = NULL} (the default),
117   then its value is determined with respect to other options: if
118   \code{type = "phylogram"} then `node.pos = 1'; if \code{type =
119     "cladogram"} and \code{use.edge.length = FALSE} then `node.pos = 2';
120   if \code{type = "cladogram"} and \code{use.edge.length = TRUE} then
121   `node.pos = 1'. Remember that in this last situation, the branch
122   lengths make sense when projected on the x-axis.
123
124   If \code{adj} is not specified, then the value is determined with
125   respect to \code{direction}: if \code{direction = "leftwards"} then
126   \code{adj = 1} (0 otherwise).
127
128   If the arguments \code{x.lim} and \code{y.lim} are not specified by the
129   user, they are determined roughly by the function. This may not always
130   give a nice result: the user may check these values with the
131   (invisibly) returned list (see ``Value:'').
132
133   If you resize manually the graphical device (windows or X11) you may
134   need to replot the tree.
135 }
136 \note{
137   The argument \code{asp} cannot be passed with \code{\dots}.
138 }
139 \value{
140   \code{plot.phylo} returns invisibly a list with the following
141   components which values are those used for the current plot:
142
143   \item{type}{}
144   \item{use.edge.length}{}
145   \item{node.pos}{}
146   \item{show.tip.label}{}
147   \item{show.node.label}{}
148   \item{font}{}
149   \item{cex}{}
150   \item{adj}{}
151   \item{srt}{}
152   \item{no.margin}{}
153   \item{label.offset}{}
154   \item{x.lim}{}
155   \item{y.lim}{}
156   \item{direction}{}
157   \item{tip.color}{}
158   \item{Ntip}{}
159   \item{Nnode}{}
160 }
161 \author{Emmanuel Paradis \email{Emmanuel.Paradis@mpl.ird.fr}}
162 \seealso{
163   \code{\link{read.tree}}, \code{\link{add.scale.bar}},
164   \code{\link{axisPhylo}}, \code{\link{nodelabels}},
165   \code{\link[graphics]{plot}} for the basic
166   plotting function in R
167 }
168 \examples{
169 ### An extract from Sibley and Ahlquist (1990)
170 cat("(((Strix_aluco:4.2,Asio_otus:4.2):3.1,",
171    "Athene_noctua:7.3):6.3,Tyto_alba:13.5);",
172    file = "ex.tre", sep = "\n")
173 tree.owls <- read.tree("ex.tre")
174 plot(tree.owls)
175 unlink("ex.tre") # delete the file "ex.tre"
176
177 ### Show the types of trees.
178 layout(matrix(1:6, 3, 2))
179 plot(tree.owls, main = "With branch lengths")
180 plot(tree.owls, type = "c")
181 plot(tree.owls, type = "u")
182 plot(tree.owls, use.edge.length = FALSE, main = "Without branch lengths")
183 plot(tree.owls, type = "c", use.edge.length = FALSE)
184 plot(tree.owls, type = "u", use.edge.length = FALSE)
185 layout(matrix(1))
186
187 data(bird.orders)
188 ### using random colours and thickness
189 plot(bird.orders,
190      edge.color = sample(colors(), length(bird.orders$edge)/2),
191      edge.width = sample(1:10, length(bird.orders$edge)/2, replace = TRUE))
192 title("Random colours and branch thickness")
193 ### rainbow colouring...
194 X <- c("red", "orange", "yellow", "green", "blue", "purple")
195 plot(bird.orders,
196      edge.color = sample(X, length(bird.orders$edge)/2, replace = TRUE),
197      edge.width = sample(1:10, length(bird.orders$edge)/2, replace = TRUE))
198 title("Rainbow colouring")
199 plot(bird.orders, type = "c", use.edge.length = FALSE,
200      edge.color = sample(X, length(bird.orders$edge)/2, replace = TRUE),
201      edge.width = rep(5, length(bird.orders$edge)/2))
202 segments(rep(0, 6), 6.5:1.5, rep(2, 6), 6.5:1.5, lwd = 5, col = X)
203 text(rep(2.5, 6), 6.5:1.5, paste(X, "..."), adj = 0)
204 title("Character mapping...")
205 plot(bird.orders, "u", font = 1, cex = 0.75)
206 data(bird.families)
207 plot(bird.families, "u", lab4ut = "axial", font = 1, cex = 0.5)
208 plot(bird.families, "r", font = 1, cex = 0.5)
209 ### cladogram with oblique tip labels
210 plot(bird.orders, "c", FALSE, direction = "u", srt = -40, x.lim = 25.5)
211 ### facing trees with different informations...
212 tr <- bird.orders
213 tr$tip.label <- rep("", 23)
214 layout(matrix(1:2, 1, 2), c(5, 4))
215 plot(bird.orders, "c", FALSE, adj = 0.5, no.margin = TRUE, label.offset = 0.8,
216      edge.color = sample(X, length(bird.orders$edge)/2, replace = TRUE),
217      edge.width = rep(5, length(bird.orders$edge)/2))
218 text(7.5, 23, "Facing trees with\ndifferent informations", font = 2)
219 plot(tr, "p", direction = "l", no.margin = TRUE,
220      edge.width = sample(1:10, length(bird.orders$edge)/2, replace = TRUE))
221 ### Recycling of arguments gives a lot of possibilities
222 ### for tip labels:
223 plot(bird.orders, tip.col = c(rep("red", 5), rep("blue", 18)),
224      font = c(rep(3, 5), rep(2, 17), 1))
225 plot(bird.orders, tip.col = c("blue", "green"),
226      cex = 23:1/23 + .3, font = 1:3)
227 co <- c(rep("blue", 9), rep("green", 35))
228 plot(bird.orders, "f", edge.col = co)
229 plot(bird.orders, edge.col = co)
230 layout(1)
231 }
232 \keyword{hplot}