From f512087dd94a7dc3462a9f31b48f61214cdc0f5e Mon Sep 17 00:00:00 2001 From: paradis Date: Thu, 23 Jul 2009 08:13:39 +0000 Subject: [PATCH] fixing add.scale.bar() git-svn-id: https://svn.mpl.ird.fr/ape/dev/ape@84 6e262413-ae40-0410-9e79-b911bd7a66b7 --- ChangeLog | 9 +++++++++ DESCRIPTION | 4 ++-- R/scales.R | 41 +++++++++++++++++++++++++++++++++++------ Thanks | 2 +- man/add.scale.bar.Rd | 12 ++++++------ 5 files changed, 53 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index c3a2a84..678bba7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ + CHANGES IN APE VERSION 2.3-3 + + +BUG FIXES + + o + + + CHANGES IN APE VERSION 2.3-2 diff --git a/DESCRIPTION b/DESCRIPTION index 8cf6cde..55c662c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ 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 diff --git a/R/scales.R b/R/scales.R index c8da7e7..01f23f5 100644 --- a/R/scales.R +++ b/R/scales.R @@ -1,24 +1,53 @@ -## 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, ...) diff --git a/Thanks b/Thanks index abbeca8..c9fea53 100644 --- a/Thanks +++ b/Thanks @@ -5,7 +5,7 @@ Many users gave important feed-back with their encouragements, 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. diff --git a/man/add.scale.bar.Rd b/man/add.scale.bar.Rd index 3ae6e59..57a1daa 100644 --- a/man/add.scale.bar.Rd +++ b/man/add.scale.bar.Rd @@ -2,11 +2,11 @@ \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}.} @@ -17,9 +17,9 @@ add.scale.bar(x = 0, y = 1, length = NULL, ...) 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 -- 2.39.2