1 ## scales.R (2009-10-02)
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-2009 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, y, length = NULL, ...)
15 lastPP <- get("last_plot.phylo", envir = .PlotPhyloEnv)
16 direc <- lastPP$direction
17 if (is.null(length)) {
19 if (direc %in% c("rightwards", "leftwards")) diff(range(lastPP$xx))
20 else diff(range(lastPP$yy))
21 nb.digit <- ceiling(log10(nb.digit)) - 2
22 length <- eval(parse(text = paste("1e", nb.digit, sep = "")))
25 if (missing(x) || missing(y))
46 segments(x, y, x + length, y)
47 text(x + length * 1.1, y, as.character(length), adj = c(0, 0.5), ...)
50 segments(x - length, y, x, y)
51 text(x - length * 1.1, y, as.character(length), adj = c(1, 0.5), ...)
54 segments(x, y, x, y + length)
55 text(x, y + length * 1.1, as.character(length), adj = c(0, 0.5), srt = 90, ...)
58 segments(x, y - length, x, y)
59 text(x, y - length * 1.1, as.character(length), adj = c(0, 0.5), srt = 270, ...)
63 axisPhylo <- function(side = 1, ...)
65 lastPP <- get("last_plot.phylo", envir = .PlotPhyloEnv)
66 if (lastPP$type %in% c("phylogram", "cladogram")) {
67 if (lastPP$direction %in% c("rightwards", "leftwards")) {
68 x <- pretty(lastPP$xx)
69 if (lastPP$direction == "rightwards") maxi <- max(lastPP$xx)
71 maxi <- min(lastPP$xx)
75 x <- pretty(lastPP$yy)
76 if (lastPP$direction == "upwards") maxi <- max(lastPP$yy)
78 maxi <- min(lastPP$yy)
83 axis(side = side, at = c(maxi - x), labels = abs(x), ...)