1 ## scales.R (2008-02-28)
3 ## Add a Scale Bar or Axis to a Phylogeny Plot
5 ## add.scale.bar: add a scale bar to a phylogeny plot
6 ## axisPhylo: add a scale axis on the side of a phylogeny plot
8 ## Copyright 2002-2008 Emmanuel Paradis
10 ## This file is part of the R-package `ape'.
11 ## See the file ../COPYING for licensing issues.
13 add.scale.bar <- function(x = 0, y = 1, length = NULL, ...)
15 lastPP <- get("last_plot.phylo", envir = .PlotPhyloEnv)
16 if (is.null(length)) {
17 nb.digit <- ceiling(log10(mean(lastPP$xx))) - 2
18 length <- eval(parse(text = paste("1e", nb.digit, sep = "")))
20 segments(x, y, x + length, y)
21 text(x + length * 1.1, y, as.character(length), adj = c(0, 0.5), ...)
24 axisPhylo <- function(side = 1, ...)
26 lastPP <- get("last_plot.phylo", envir = .PlotPhyloEnv)
27 if (lastPP$type %in% c("phylogram", "cladogram")) {
28 if (lastPP$direction %in% c("rightwards", "leftwards")) {
29 x <- pretty(lastPP$xx)
30 if (lastPP$direction == "rightwards") maxi <- max(lastPP$xx)
32 maxi <- min(lastPP$xx)
36 x <- pretty(lastPP$yy)
37 if (lastPP$direction == "upwards") maxi <- max(lastPP$yy)
39 maxi <- min(lastPP$yy)
44 axis(side = side, at = c(maxi - x), labels = abs(x), ...)