]> git.donarmstrong.com Git - ape.git/blobdiff - R/scales.R
various changes and fixes
[ape.git] / R / scales.R
index 01f23f5fe96c8e263baf0f319284353de9b5b2ce..378f985cc4c434e3104c2a3498844aba991540a2 100644 (file)
 add.scale.bar <- function(x, y, length = NULL, ...)
 {
     lastPP <- get("last_plot.phylo", envir = .PlotPhyloEnv)
+    direc <- lastPP$direction
     if (is.null(length)) {
         nb.digit <-
-          if (lastPP$direction %in% c("rightwards", "leftwards")) diff(range(lastPP$xx))
+          if (direc %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 = "")))
     }
-    if (missing(x) || missing(y)) {
-        switch(lastPP$direction,
+
+    if (missing(x) || missing(y))
+        switch(direc,
                "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, ...)
-               }
-         )
-    }
+               })
+
+    switch(direc,
+           "rightwards" = {
+               segments(x, y, x + length, y)
+               text(x + length * 1.1, y, as.character(length), adj = c(0, 0.5), ...)
+           },
+           "leftwards" = {
+               segments(x - length, y, x, y)
+               text(x - length * 1.1, y, as.character(length), adj = c(1, 0.5), ...)
+           },
+           "upwards" = {
+               segments(x, y, x, y + length)
+               text(x, y + length * 1.1, as.character(length), adj = c(0, 0.5), srt = 90, ...)
+           },
+           "downwards" = {
+               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, ...)