X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=R%2Fscales.R;h=2243278b19e8b94c9c6b6e652c32687eb39f9a92;hb=0875d81d5ba5e6dfe79d42c21b0284b674c73949;hp=614db24540e46a4b0df02f7624e21abe165ec63d;hpb=6a2fafede27a5cf6a5aafef7c9b56e78635eaeb4;p=ape.git diff --git a/R/scales.R b/R/scales.R index 614db24..2243278 100644 --- a/R/scales.R +++ b/R/scales.R @@ -1,4 +1,4 @@ -## scales.R (2009-10-02) +## scales.R (2009-12-16) ## Add a Scale Bar or Axis to a Phylogeny Plot @@ -10,7 +10,7 @@ ## This file is part of the R-package `ape'. ## See the file ../COPYING for licensing issues. -add.scale.bar <- function(x, y, length = NULL, ...) +add.scale.bar <- function(x, y, length = NULL, ask = FALSE, ...) { lastPP <- get("last_plot.phylo", envir = .PlotPhyloEnv) direc <- lastPP$direction @@ -22,24 +22,36 @@ add.scale.bar <- function(x, y, length = NULL, ...) length <- eval(parse(text = paste("1e", nb.digit, sep = ""))) } - if (missing(x) || missing(y)) - switch(direc, - "rightwards" = { - x <- 0 - y <- 1 - }, - "leftwards" = { - x <- max(lastPP$xx) - y <- 1 - }, - "upwards" = { - x <- max(lastPP$xx) - y <- 0 - }, - "downwards" = { - x <- 1 - y <- max(lastPP$yy) - }) + if (ask) { + cat("\nClick where you want to draw the bar\n") + x <- unlist(locator(1)) + y <- x[2] + x <- x[1] + } else if (missing(x) || missing(y)) { + if (lastPP$type %in% c("phylogram", "cladogram")) { + switch(direc, + "rightwards" = { + x <- 0 + y <- 1 + }, + "leftwards" = { + x <- max(lastPP$xx) + y <- 1 + }, + "upwards" = { + x <- max(lastPP$xx) + y <- 0 + }, + "downwards" = { + x <- 1 + y <- max(lastPP$yy) + }) + } else { + direc <- "rightwards" # just to be sure for below + x <- lastPP$x.lim[1] + y <- lastPP$y.lim[1] + } + } switch(direc, "rightwards" = {