]> git.donarmstrong.com Git - ape.git/blob - R/scales.R
current 2.1 release
[ape.git] / R / scales.R
1 ## scales.R (2004-12-18)
2
3 ##   Add a Scale Bar or Axis to a Phylogeny Plot
4
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
7
8 ## Copyright 2002-2004 Emmanuel Paradis
9
10 ## This file is part of the R-package `ape'.
11 ## See the file ../COPYING for licensing issues.
12
13 add.scale.bar <- function(x = 0, y = 1, length = NULL, ...)
14 {
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 = "")))
18     }
19     segments(x, y, x + length, y)
20     text(x + length * 1.1, y, as.character(length), adj = c(0, 0.5), ...)
21 }
22
23 axisPhylo <- function(side = 1, ...)
24 {
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)
30             else {
31                 maxi <- min(.last_plot.phylo$xx)
32                 x <- -x
33             }
34         } else {
35             x <- pretty(.last_plot.phylo$yy)
36             if (.last_plot.phylo$direction == "upwards")
37             maxi <- max(.last_plot.phylo$yy)
38             else {
39                 maxi <- min(.last_plot.phylo$yy)
40                 x <- -x
41             }
42         }
43     }
44     axis(side = side, at = c(maxi - x), labels = abs(x), ...)
45 }