1 ## scales.R (2004-12-18)
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-2004 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 if (is.null(length)) {
16 nb.digit <- ceiling(log10(mean(.last_plot.phylo$xx))) - 2
17 length <- eval(parse(text = paste("1e", nb.digit, sep = "")))
19 segments(x, y, x + length, y)
20 text(x + length * 1.1, y, as.character(length), adj = c(0, 0.5), ...)
23 axisPhylo <- function(side = 1, ...)
25 if (.last_plot.phylo$type %in% c("phylogram", "cladogram")) {
26 if (.last_plot.phylo$direction %in% c("rightwards", "leftwards")) {
27 x <- pretty(.last_plot.phylo$xx)
28 if (.last_plot.phylo$direction == "rightwards")
29 maxi <- max(.last_plot.phylo$xx)
31 maxi <- min(.last_plot.phylo$xx)
35 x <- pretty(.last_plot.phylo$yy)
36 if (.last_plot.phylo$direction == "upwards")
37 maxi <- max(.last_plot.phylo$yy)
39 maxi <- min(.last_plot.phylo$yy)
44 axis(side = side, at = c(maxi - x), labels = abs(x), ...)