1 ## ltt.plot.R (2007-12-22)
3 ## Lineages Through Time Plot
5 ## Copyright 2002-2007 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 (class(phy) != "phylo") stop('object "phy" is not of class "phylo"')
13 time <- sort(branching.times(phy), decreasing = TRUE)
14 N <- 1:(length(time) + 1)
15 plot(-c(time, 0), N, xlab = xlab, ylab = ylab,
16 xaxs = "r", yaxs = "r", type = "S", ...)
19 ltt.lines <- function(phy, ...)
21 time <- sort(branching.times(phy), decreasing = TRUE)
22 N <- 1:(length(time) + 1)
23 lines(-c(time, 0), N, type = "S", ...)
26 mltt.plot <- function(phy, ..., dcol = TRUE, dlty = FALSE, legend = TRUE,
27 xlab = "Time", ylab = "N")
29 ltt.xy <- function(phy) {
30 x <- -c(sort(branching.times(phy), decreasing = TRUE), 0)
35 if (class(phy) == "phylo") {
36 TREES <- list(ltt.xy(phy))
37 names(TREES) <- deparse(substitute(phy))
38 } else { # a list of trees
39 TREES <- lapply(phy, ltt.xy)
40 names(TREES) <- names(phy)
45 mc <- as.character(match.call())[-(1:2)]
48 if (class(dts[[i]]) == "phylo") {
49 a <- list(ltt.xy(dts[[i]]))
51 } else { # a list of trees
52 a <- lapply(dts[[i]], ltt.xy)
53 names(a) <- names(dts[[i]])
59 xl <- c(min(unlist(lapply(TREES, function(x) min(x[, 1])))), 0)
60 yl <- c(1, max(unlist(lapply(TREES, function(x) max(x[, 2])))))
62 plot(0, 0, type = "n", xlim = xl, ylim = yl, xaxs = "r", yaxs = "r",
63 xlab = xlab, ylab = ylab)
65 lty <- if (!dlty) rep(1, n) else 1:n
66 col <- if (!dcol) rep(1, n) else topo.colors(n)
69 lines(TREES[[i]], col = col[i], lty = lty[i], type = "S")
72 legend(xl[1], yl[2], legend = names(TREES),
73 lty = lty, col = col, bty = "n")