X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=R%2Fidentify.phylo.R;h=64ecc38734dd2be60e6dd72edf87eccbe45be497;hb=46bc16a7531d871fccb6ea7c2a31d980aac21bd1;hp=62476db1c437f5880e4b0ab631aa37724828a696;hpb=d88302b4735b5b7c9132387090bb592d906fe1cb;p=ape.git diff --git a/R/identify.phylo.R b/R/identify.phylo.R index 62476db..64ecc38 100644 --- a/R/identify.phylo.R +++ b/R/identify.phylo.R @@ -1,33 +1,44 @@ -## identify.phylo.R (2008-01-14) +## identify.phylo.R (2011-03-23) ## Graphical Identification of Nodes and Tips -## Copyright 2008 Emmanuel Paradis +## Copyright 2008-2011 Emmanuel Paradis ## This file is part of the R-package `ape'. ## See the file ../COPYING for licensing issues. identify.phylo <- function(x, nodes = TRUE, tips = FALSE, - labels = FALSE, ...) + labels = FALSE, quiet = FALSE, ...) { - cat("Click close to a node of the tree...\n") + if (!quiet) + cat("Click close to a node of the tree...\n") xy <- locator(1) - Ntip <- .last_plot.phylo$Ntip - d <- sqrt((xy$x - .last_plot.phylo$xx)^2 + - (xy$y - .last_plot.phylo$yy)^2) + if (is.null(xy)) return(NULL) + lastPP <- get("last_plot.phylo", envir = .PlotPhyloEnv) + ## rescale the coordinates (especially if the x- and + ## y-scales are very different): + pin <- par("pin") + rescaleX <- pin[1]/max(lastPP$xx) + xx <- rescaleX * lastPP$xx + rescaleY <- pin[2]/max(lastPP$yy) + yy <- rescaleY * lastPP$yy + xy$x <- rescaleX * xy$x + xy$y <- rescaleY * xy$y + ## end of rescaling + d <- (xy$x - xx)^2 + (xy$y - yy)^2 # no need to sqrt() NODE <- which.min(d) res <- list() - if (NODE <= Ntip) { + if (NODE <= lastPP$Ntip) { res$tips <- if (labels) x$tip.label[NODE] else NODE return(res) } if (tips) { - TIPS <- prop.part(x)[[NODE - Ntip]] + TIPS <- prop.part(x)[[NODE - lastPP$Ntip]] res$tips <- if (labels) x$tip.label[TIPS] else TIPS } if (nodes) { if (is.null(x$node.label)) labels <- FALSE - res$nodes <- if (labels) x$node.label[NODE - Ntip] else NODE + res$nodes <- if (labels) x$node.label[NODE - lastPP$Ntip] else NODE } res }