]> git.donarmstrong.com Git - ape.git/blobdiff - R/ltt.plot.R
a few fixes
[ape.git] / R / ltt.plot.R
index 17a1d3152248e4e4201c52a2442dd7f78f60c203..520294fc9cb68c4313637c65bf5b6f3e33bbe525 100644 (file)
@@ -1,8 +1,8 @@
-## ltt.plot.R (2011-09-24)
+## ltt.plot.R (2012-03-05)
 
 ##    Lineages Through Time Plot
 
-## Copyright 2002-2011 Emmanuel Paradis
+## Copyright 2002-2012 Emmanuel Paradis
 
 ## This file is part of the R-package `ape'.
 ## See the file ../COPYING for licensing issues.
@@ -106,14 +106,24 @@ mltt.plot <-
                 a <- lapply(dts[[i]], ltt.plot.coords, backward = backward, tol = tol)
                 names(a) <- names(dts[[i]])
                 if (is.null(names(a)))
-                    names(a) <- paste(deparse(substitute(phy)), "-", 1:length(a))
+                    names(a) <- paste(deparse(substitute(phy)), "-", seq_along(a))
             }
             TREES <- c(TREES, a)
         }
     }
     n <- length(TREES)
-    xl <- c(min(unlist(lapply(TREES, function(x) min(x[, 1])))), 0)
-    yl <- c(1, max(unlist(lapply(TREES, function(x) max(x[, 2])))))
+    range.each.tree <- sapply(TREES, function(x) range(x[, 1]))
+    xl <- range(range.each.tree)
+    yl <- c(1, max(sapply(TREES, function(x) max(x[, 2]))))
+
+    ## if backward is FALSE, we have to rescale the time scales of each tree:
+    if (!backward) {
+        for (i in seq_along(TREES)) {
+            tmp <- TREES[[i]]
+            tmp[, 1] <- tmp[, 1] + xl[2] - range.each.tree[2, i]
+            TREES[[i]] <- tmp
+        }
+    }
 
     plot.default(NA, type = "n", xlim = xl, ylim = yl, xaxs = "r",
                  yaxs = "r", xlab = xlab, ylab = ylab, log = log)