Package: ape
-Version: 2.3-2
-Date: 2009-07-17
+Version: 2.3-3
+Date: 2009-07-22
Title: Analyses of Phylogenetics and Evolution
Author: Emmanuel Paradis, Ben Bolker, Julien Claude, Hoa Sien Cuong, Richard Desper, Benoit Durand, Julien Dutheil, Olivier Gascuel, Gangolf Jobb, Christoph Heibl, Daniel Lawson, Vincent Lefort, Pierre Legendre, Jim Lemon, Yvonnick Noel, Johan Nylander, Rainer Opgen-Rhein, Korbinian Strimmer, Damien de Vienne
Maintainer: Emmanuel Paradis <Emmanuel.Paradis@ird.fr>
-## scales.R (2008-02-28)
+## scales.R (2009-07-23)
## Add a Scale Bar or Axis to a Phylogeny Plot
## add.scale.bar: add a scale bar to a phylogeny plot
## axisPhylo: add a scale axis on the side of a phylogeny plot
-## Copyright 2002-2008 Emmanuel Paradis
+## Copyright 2002-2009 Emmanuel Paradis
## This file is part of the R-package `ape'.
## See the file ../COPYING for licensing issues.
-add.scale.bar <- function(x = 0, y = 1, length = NULL, ...)
+add.scale.bar <- function(x, y, length = NULL, ...)
{
lastPP <- get("last_plot.phylo", envir = .PlotPhyloEnv)
if (is.null(length)) {
- nb.digit <- ceiling(log10(mean(lastPP$xx))) - 2
+ nb.digit <-
+ if (lastPP$direction %in% c("rightwards", "leftwards")) diff(range(lastPP$xx))
+ else diff(range(lastPP$yy))
+ nb.digit <- ceiling(log10(nb.digit)) - 2
length <- eval(parse(text = paste("1e", nb.digit, sep = "")))
}
- segments(x, y, x + length, y)
- text(x + length * 1.1, y, as.character(length), adj = c(0, 0.5), ...)
+ if (missing(x) || missing(y)) {
+ switch(lastPP$direction,
+ "rightwards" = {
+ x <- 0
+ y <- 1
+ segments(x, y, x + length, y)
+ text(x + length * 1.1, y, as.character(length), adj = c(0, 0.5), ...)
+ },
+ "leftwards" = {
+ x <- max(lastPP$xx)
+ y <- 1
+ segments(x - length, y, x, y)
+ text(x - length * 1.1, y, as.character(length), adj = c(1, 0.5), ...)
+ },
+ "upwards" = {
+ x <- max(lastPP$xx)
+ y <- 0
+ segments(x, y, x, y + length)
+ text(x, y + length * 1.1, as.character(length), adj = c(0, 0.5), srt = 90, ...)
+ },
+ "downwards" = {
+ x <- 1
+ y <- max(lastPP$yy)
+ segments(x, y - length, x, y)
+ text(x, y - length * 1.1, as.character(length), adj = c(0, 0.5), srt = 270, ...)
+ }
+ )
+ }
}
axisPhylo <- function(side = 1, ...)
comments, or bug reports: thanks to all of you!
Significant bug fixes were provided by Cécile Ané, James Bullard,
-Éric Durand, Olivier François, Rich FitzJohn Bret Larget, Nick Matzke,
+Éric Durand, Olivier François, Rich FitzJohn, Bret Larget, Nick Matzke,
Elizabeth Purdom, Dan Rabosky, Klaus Schliep, Tim Wallstrom, Li-San
Wang, Yan Wong, and Peter Wragg. Contact me if I forgot someone.
\alias{add.scale.bar}
\title{Add a Scale Bar to a Phylogeny Plot}
\usage{
-add.scale.bar(x = 0, y = 1, length = NULL, ...)
+add.scale.bar(x, y, length = NULL, ...)
}
\arguments{
- \item{x}{x location of the bar.}
- \item{y}{y location of the bar.}
+ \item{x}{x location of the bar (can be left missing).}
+ \item{y}{y location of the bar (can be left missing).}
\item{length}{a numeric value giving the length of the scale bar. If
none is supplied, a value is calculated from the data.}
\item{...}{further arguments to be passed to \code{text}.}
device.
}
\details{
- As from version 1.4 of ape, the options of this function have been
- redefined, and have now default values. By default, the scale bar is
- plotted on the left bottom corner of the plot.
+ By default, the bar is placed in a corner of the graph depending on
+ the direction of the tree. Otherwise both \code{x} and \code{y} must
+ be specified (if only one is given it is ignored).
The further arguments (\code{...}) are used to format the text. They
may be \code{font}, \code{cex}, \code{col}, and so on (see examples