From: paradis Date: Mon, 1 Feb 2010 17:20:18 +0000 (+0000) Subject: final packaging for ape 2.5! X-Git-Url: https://git.donarmstrong.com/?p=ape.git;a=commitdiff_plain;h=2db1869a11e5d88afb74ddeea5ea1c5c3aadf249 final packaging for ape 2.5! git-svn-id: https://svn.mpl.ird.fr/ape/dev/ape@110 6e262413-ae40-0410-9e79-b911bd7a66b7 --- diff --git a/ChangeLog b/ChangeLog index f8a21e4..b8d7c84 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,8 +5,8 @@ NEW FEATURES o The new function parafit by Pierre Legendre tests for the coevolution between hosts and parasites. It has a companion - function, pcoa, that does principal coordinate decomposition. The - latter has a biplot method. + function, pcoa, that does principal coordinate decomposition. + The latter has a biplot method. o The new function lmorigin by Pierre Legendre performs multiple regression through the origin with testing by permutation. @@ -17,6 +17,12 @@ NEW FEATURES o The new function delta.plot does a delta plot following Holland et al. (2002, Mol. Biol. Evol. 12:2051). + o The new function edges draws additional branches between any nodes + and/or tips on a plotted tree. + + o The new function fancyarrows enhances arrows from graphics with + triangle and harpoon heads; it can be called from edges(). + o add.scale.bar() has a new option 'ask' to draw interactively. o The branch length score replaces the geodesic distance in dist.topo. diff --git a/DESCRIPTION b/DESCRIPTION index e21013f..0b756c1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: ape Version: 2.5 -Date: 2010-01-21 +Date: 2010-02-01 Title: Analyses of Phylogenetics and Evolution Author: Emmanuel Paradis, Ben Bolker, Julien Claude, Hoa Sien Cuong, Richard Desper, Benoit Durand, Julien Dutheil, Olivier Gascuel, Gangolf Jobb, Christoph Heibl, Daniel Lawson, Vincent Lefort, Pierre Legendre, Jim Lemon, Yvonnick Noel, Johan Nylander, Rainer Opgen-Rhein, Korbinian Strimmer, Damien de Vienne Maintainer: Emmanuel Paradis diff --git a/R/nodelabels.R b/R/nodelabels.R index 019563d..5526b01 100644 --- a/R/nodelabels.R +++ b/R/nodelabels.R @@ -1,8 +1,8 @@ -## nodelabels.R (2009-09-30) +## nodelabels.R (2010-01-30) ## Labelling Trees -## Copyright 2004-2009 Emmanuel Paradis, 2006 Ben Bolker, and 2006 Jim Lemon +## Copyright 2004-2010 Emmanuel Paradis, 2006 Ben Bolker, and 2006 Jim Lemon ## This file is part of the R-package `ape'. ## See the file ../COPYING for licensing issues. @@ -168,3 +168,90 @@ edgelabels <- function(text, edge, adj = c(0.5, 0.5), frame = "rect", BOTHlabels(text, sel, XX, YY, adj, frame, pch, thermo, pie, piecol, col, bg, ...) } + +edges <- function(nodes0, nodes1, arrows = 0, type = "classical", ...) +{ + type <- match.arg(type, c("classical", "triangle", "harpoon")) + lastPP <- get("last_plot.phylo", envir = .PlotPhyloEnv) + ## we do the recycling if necessary: + if (length(nodes0) != length(nodes1)) { + tmp <- cbind(nodes0, nodes1) + nodes0 <- tmp[, 1] + nodes1 <- tmp[, 2] + } + x0 <- lastPP$xx[nodes0] + y0 <- lastPP$yy[nodes0] + x1 <- lastPP$xx[nodes1] + y1 <- lastPP$yy[nodes1] + if (arrows) + if (type == "classical") + graphics::arrows(x0, y0, x1, y1, code = arrows, ...) + else + fancyarrows(x0, y0, x1, y1, code = arrows, type = type, ...) + else + graphics::segments(x0, y0, x1, y1, ...) +} + +fancyarrows <- + function(x0, y0, x1, y1, length = 0.25, angle = 30, code = 2, + col = par("fg"), lty = par("lty"), lwd = par("lwd"), + type = "triangle", ...) +{ + foo <- function(x0, y0, x1, y1) { + ## important to correct with these parameters cause + ## the coordinate system will likely not be Cartesian + pin <- par("pin") + usr <- par("usr") + A1 <- pin[1]/diff(usr[1:2]) + A2 <- pin[2]/diff(usr[3:4]) + x0 <- x0 * A1 + y0 <- y0 * A2 + x1 <- x1 * A1 + y1 <- y1 * A2 + atan2(y1 - y0, x1 - x0) + } + arrow.triangle <- function(x, y) { + beta <- alpha - angle/2 + xa <- xinch(length * cos(beta)) + x + ya <- yinch(length * sin(beta)) + y + beta <- beta + angle + xb <- xinch(length * cos(beta)) + x + yb <- yinch(length * sin(beta)) + y + n <- length(x) + col <- rep(col, length.out = n) + for (i in 1:n) + polygon(c(x[i], xa[i], xb[i]), c(y[i], ya[i], yb[i]), + col = col[i], border = col[i]) + list((xa + xb)/2, (ya + yb)/2) + } + arrow.harpoon <- function(x, y) { + beta <- alpha - angle/2 + xa <- xinch(length * cos(beta)) + x + ya <- yinch(length * sin(beta)) + y + beta <- alpha + angle/2 + xb <- xinch(length * cos(beta)) + x + yb <- yinch(length * sin(beta)) + y + xc <- x/2 + (xa + xb)/4 + yc <- y/2 + (ya + yb)/4 + n <- length(x) + col <- rep(col, length.out = n) + for (i in 1:n) + polygon(c(x[i], xa[i], xc[i], xb[i]), + c(y[i], ya[i], yc[i], yb[i]), + col = col[i], border = col[i]) + list(xc, yc) + } + + type <- match.arg(type, c("triangle", "harpoon")) + angle <- pi*angle/180 # degree -> radian + alpha <- foo(x0, y0, x1, y1) # angle of segment with x-axis + ## alpha is in [-pi, pi] + + FUN <- if (type == "triangle") arrow.triangle else arrow.harpoon + XY0 <- if (code == 1 || code == 3) FUN(x0, y0) else list(x0, y0) + if (code >= 2) { + alpha <- (alpha + pi) %% (2 * pi) + XY1 <- FUN(x1, y1) + } else XY1 <- list(x1, y1) + segments(XY0[[1]], XY0[[2]], XY1[[1]], XY1[[2]], col = col, lty = lty, lwd = lwd, ...) +} diff --git a/man/edges.Rd b/man/edges.Rd new file mode 100644 index 0000000..4153863 --- /dev/null +++ b/man/edges.Rd @@ -0,0 +1,50 @@ +\name{edges} +\alias{edges} +\alias{fancyarrows} +\title{Draw Additional Edges on a Plotted Tree} +\description{ + \code{edges} draws edges on a plotted tree. \code{fancyarrows} + enhances \code{\link[graphics]{arrows}} with triangle and harpoon + heads; it can be called from \code{edges}. +} +\usage{ +edges(nodes0, nodes1, arrows = 0, type = "classical", ...) +fancyarrows(x0, y0, x1, y1, length = 0.25, angle = 30, code = 2, + col = par("fg"), lty = par("lty"), lwd = par("lwd"), + type = "triangle", ...) +} +\arguments{ + \item{nodes0, nodes1}{vectors of integers giving the tip and/or node + numbers where to start and to end the edges (eventually recycled).} + \item{arrows}{an integer between 0 and 3; 0: lines (the default); 1: + an arrow head is drawn at \code{nodes0}; 2: at \code{nodes1}; 3: + both.} + \item{type}{if the previous argument is not 0, the type of arrow head: + \code{"classical"} (just lines, the default), \code{"triangle"}, + \code{"harpoon"}, or any unambiguous abbreviations of these. For + \code{fancyarrows} only the last two are available.} + \item{x0, y0, x1, y1}{the coordinates of the start and end points for + \code{fancyarrows} (these are not recycled and so should be vectors + of the same length).} + \item{length, angle, code, col, lty, lwd}{default options similar to + those of \code{\link[graphics]{arrows}}.} + \item{\dots}{further arguments passed to \code{\link[graphics]{segments}}.} +} +\details{ + The first function is helpful when drawing reticulations on a phylogeny, + especially if computed from the edge matrix. +} +\author{Emmanuel Paradis} +\seealso{ + \code{\link{plot.phylo}}, \code{\link{nodelabels}} +} +\examples{ +set.seed(2) +tr <- rcoal(6) +plot(tr, "c") +edges(10, 9, col = "red", lty = 2) +edges(10:11, 8, col = c("blue", "green")) # recycling of 'nodes1' +edges(1, 2, lwd = 2, type = "h", arrows = 3, col = "green") +nodelabels() +} +\keyword{aplot} diff --git a/man/nodelabels.Rd b/man/nodelabels.Rd index 56c4da1..292dc13 100644 --- a/man/nodelabels.Rd +++ b/man/nodelabels.Rd @@ -83,7 +83,7 @@ edgelabels(text, edge, adj = c(0.5, 0.5), frame = "rect", \author{Emmanuel Paradis \email{Emmanuel.Paradis@mpl.ird.fr}, Ben Bolker \email{bolker@zoo.ufl.edu}, and Jim Lemon} \seealso{ - \code{\link{plot.phylo}} + \code{\link{plot.phylo}}, \code{\link{edges}} } \examples{ tr <- read.tree(text = "((Homo,Pan),Gorilla);") diff --git a/man/plot.phylo.Rd b/man/plot.phylo.Rd index 52a726a..fa2658f 100644 --- a/man/plot.phylo.Rd +++ b/man/plot.phylo.Rd @@ -164,7 +164,7 @@ \seealso{ \code{\link{read.tree}}, \code{\link{add.scale.bar}}, \code{\link{axisPhylo}}, \code{\link{nodelabels}}, - \code{\link[graphics]{plot}} for the basic + \code{\link{edges}}, \code{\link[graphics]{plot}} for the basic plotting function in R } \examples{ diff --git a/man/rTraitDisc.Rd b/man/rTraitDisc.Rd index 967042e..ed1919d 100644 --- a/man/rTraitDisc.Rd +++ b/man/rTraitDisc.Rd @@ -42,7 +42,7 @@ rTraitDisc(phy, model = "ER", k = if (is.matrix(model)) ncol(model) else 2, always ignored. The arguments \code{k} and \code{rate} are ignored.} \item{A character:}{these are the same short-cuts than in the function - \link{\code{ace}}: \code{"ER"} is an equal-rates model, \code{"ARD"} + \code{\link{ace}}: \code{"ER"} is an equal-rates model, \code{"ARD"} is an all-rates-different model, and \code{"SYM"} is a symmetrical model. Note that the argument \code{rate} must be of the appropriate length, i.e., 1, \eqn{k(k - 1)}, or \eqn{k(k - 1)/2} for the three models,