- segments(x, y, x + length, y)
- text(x + length * 1.1, y, as.character(length), adj = c(0, 0.5), ...)
+
+ 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" = {
+ segments(x, y, x + length, y, col = lcol, lwd = lwd)
+ text(x + length * 1.1, y, as.character(length), adj = c(0, 0.5), ...)
+ },
+ "leftwards" = {
+ segments(x - length, y, x, y, col = lcol, lwd = lwd)
+ text(x - length * 1.1, y, as.character(length), adj = c(1, 0.5), ...)
+ },
+ "upwards" = {
+ segments(x, y, x, y + length, col = lcol, lwd = lwd)
+ text(x, y + length * 1.1, as.character(length), adj = c(0, 0.5), srt = 90, ...)
+ },
+ "downwards" = {
+ segments(x, y - length, x, y, col = lcol, lwd = lwd)
+ text(x, y - length * 1.1, as.character(length), adj = c(0, 0.5), srt = 270, ...)
+ })