]> git.donarmstrong.com Git - ape.git/blobdiff - R/scales.R
improved root()
[ape.git] / R / scales.R
index 9699b5b165ca81c4922ddfee2f86242c6d6e54d8..69c9f46d638d43d166f504ede4e4db8adaf0e382 100644 (file)
@@ -1,11 +1,11 @@
-## scales.R (2004-12-18)
+## scales.R (2008-02-08)
 
 ##   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-2004 Emmanuel Paradis
+## Copyright 2002-2008 Emmanuel Paradis
 
 ## This file is part of the R-package `ape'.
 ## See the file ../COPYING for licensing issues.
@@ -13,7 +13,8 @@
 add.scale.bar <- function(x = 0, y = 1, length = NULL, ...)
 {
     if (is.null(length)) {
-        nb.digit <- ceiling(log10(mean(.last_plot.phylo$xx))) - 2
+        nb.digit <- ceiling(log10(mean(get("last_plot.phylo$xx",
+                                           envir = .PlotPhyloEnv)))) - 2
         length <- eval(parse(text = paste("1e", nb.digit, sep = "")))
     }
     segments(x, y, x + length, y)
@@ -22,21 +23,23 @@ add.scale.bar <- function(x = 0, y = 1, length = NULL, ...)
 
 axisPhylo <- function(side = 1, ...)
 {
-    if (.last_plot.phylo$type %in% c("phylogram", "cladogram")) {
-        if (.last_plot.phylo$direction %in% c("rightwards", "leftwards")) {
-            x <- pretty(.last_plot.phylo$xx)
-            if (.last_plot.phylo$direction == "rightwards")
-              maxi <- max(.last_plot.phylo$xx)
+    type <- get("last_plot.phylo$type", envir = .PlotPhyloEnv)
+    direction <- get("last_plot.phylo$direction", envir = .PlotPhyloEnv)
+    if (type %in% c("phylogram", "cladogram")) {
+        if (direction %in% c("rightwards", "leftwards")) {
+            xx <- get("last_plot.phylo$xx", envir = .PlotPhyloEnv)
+            x <- pretty(xx)
+            if (direction == "rightwards") maxi <- max(xx)
             else {
-                maxi <- min(.last_plot.phylo$xx)
+                maxi <- min(xx)
                 x <- -x
             }
         } else {
-            x <- pretty(.last_plot.phylo$yy)
-            if (.last_plot.phylo$direction == "upwards")
-            maxi <- max(.last_plot.phylo$yy)
+            yy <- get("last_plot.phylo$yy", envir = .PlotPhyloEnv)
+            x <- pretty(yy)
+            if (direction == "upwards") maxi <- max(yy)
             else {
-                maxi <- min(.last_plot.phylo$yy)
+                maxi <- min(yy)
                 x <- -x
             }
         }