1 ## ltt.plot.R (2009-05-10)
3 ## Lineages Through Time Plot
5 ## Copyright 2002-2009 Emmanuel Paradis
7 ## This file is part of the R-package `ape'.
8 ## See the file ../COPYING for licensing issues.
10 ltt.plot <- function(phy, xlab = "Time", ylab = "N", ...)
12 if (!inherits(phy, "phylo")) stop('object "phy" is not of class "phylo"')
13 if (!is.binary.tree(phy)) phy <- multi2di(phy)
14 time <- sort(branching.times(phy), decreasing = TRUE)
15 N <- 1:(length(time) + 1)
16 plot.default(-c(time, 0), N, xlab = xlab, ylab = ylab,
17 xaxs = "r", yaxs = "r", type = "S", ...)
20 ltt.lines <- function(phy, ...)
22 if (!is.binary.tree(phy)) phy <- multi2di(phy)
23 time <- sort(branching.times(phy), decreasing = TRUE)
24 N <- 1:(length(time) + 1)
25 lines(-c(time, 0), N, type = "S", ...)
28 mltt.plot <- function(phy, ..., dcol = TRUE, dlty = FALSE, legend = TRUE,
29 xlab = "Time", ylab = "N", log = "")
31 ltt.xy <- function(phy) {
32 if (!is.binary.tree(phy)) phy <- multi2di(phy)
33 x <- -c(sort(branching.times(phy), decreasing = TRUE), 0)
38 if (inherits(phy, "phylo")) { # if a tree of class "phylo"
39 TREES <- list(ltt.xy(phy))
40 names(TREES) <- deparse(substitute(phy))
41 } else { # a list of trees
42 TREES <- lapply(phy, ltt.xy)
43 names(TREES) <- names(phy)
44 if (is.null(names(TREES)))
46 paste(deparse(substitute(phy)), "-", 1:length(TREES))
51 mc <- as.character(match.call())[-(1:2)]
54 if (class(dts[[i]]) == "phylo") {
55 a <- list(ltt.xy(dts[[i]]))
57 } else { # a list of trees
58 a <- lapply(dts[[i]], ltt.xy)
59 names(a) <- names(dts[[i]])
60 if (is.null(names(a)))
62 paste(deparse(substitute(phy)), "-", 1:length(a))
68 xl <- c(min(unlist(lapply(TREES, function(x) min(x[, 1])))), 0)
69 yl <- c(1, max(unlist(lapply(TREES, function(x) max(x[, 2])))))
71 plot.default(1, 1, type = "n", xlim = xl, ylim = yl, xaxs = "r",
72 yaxs = "r", xlab = xlab, ylab = ylab, log = log)
74 lty <- if (!dlty) rep(1, n) else 1:n
75 col <- if (!dcol) rep(1, n) else topo.colors(n)
78 lines(TREES[[i]], col = col[i], lty = lty[i], type = "S")
81 legend(xl[1], yl[2], legend = names(TREES),
82 lty = lty, col = col, bty = "n")