From 0e3fb192a3bd90922b5a41bae0a26505dc78550e Mon Sep 17 00:00:00 2001 From: paradis Date: Thu, 17 Feb 2011 17:04:12 +0000 Subject: [PATCH] bug fixes in plot.phylo git-svn-id: https://svn.mpl.ird.fr/ape/dev/ape@146 6e262413-ae40-0410-9e79-b911bd7a66b7 --- ChangeLog | 4 ++++ DESCRIPTION | 2 +- R/plot.phylo.R | 42 ++++++++++++++++++++++++++++-------------- man/corMartins.Rd | 2 +- man/rotate.Rd | 4 ---- man/vcv.phylo.Rd | 3 ++- 6 files changed, 36 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8480ce8..72198d9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -20,6 +20,10 @@ BUG FIXES o plot.phylo() did not recycle values of 'font', 'cex' and 'tip.color' correctly when type = "fan" or "radial". + o plot.phylo() ignored 'label.offset' when type = "radial", "fan", or + "unrooted" with lab4ut = "axial" (the placement of tip labels still + needs to be improved with lab4ut = "horizontal"). + OTHER CHANGES diff --git a/DESCRIPTION b/DESCRIPTION index 17dfadf..1bf01d2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: ape Version: 2.6-3 -Date: 2011-02-11 +Date: 2011-02-17 Title: Analyses of Phylogenetics and Evolution Author: Emmanuel Paradis, Ben Bolker, Julien Claude, Hoa Sien Cuong, Richard Desper, Benoit Durand, Julien Dutheil, Olivier Gascuel, Christoph Heibl, Daniel Lawson, Vincent Lefort, Pierre Legendre, Jim Lemon, Yvonnick Noel, Johan Nylander, Rainer Opgen-Rhein, Klaus Schliep, Korbinian Strimmer, Damien de Vienne Maintainer: Emmanuel Paradis diff --git a/R/plot.phylo.R b/R/plot.phylo.R index 69f0866..b2273ca 100644 --- a/R/plot.phylo.R +++ b/R/plot.phylo.R @@ -1,4 +1,4 @@ -## plot.phylo.R (2011-02-11) +## plot.phylo.R (2011-02-17) ## Plot Phylogenies @@ -351,44 +351,58 @@ plot.phylo <- function(x, type = "phylogram", use.edge.length = TRUE, y.adj[sel] <- strheight(x$tip.label)[sel] / 2 sel <- XY$axe < -pi / 4 & XY$axe > -0.75 * pi y.adj[sel] <- -strheight(x$tip.label)[sel] * 0.75 - text(xx[1:Ntip] + x.adj*cex, yy[1:Ntip] + y.adj*cex, + text(xx[1:Ntip] + x.adj * cex, yy[1:Ntip] + y.adj * cex, x$tip.label, adj = c(adj, 0), font = font, srt = srt, cex = cex, col = tip.color) } else { # if lab4ut == "axial" - adj <- as.numeric(abs(XY$axe) > pi/2) - srt <- 180*XY$axe/pi - srt[as.logical(adj)] <- srt[as.logical(adj)] - 180 + adj <- abs(XY$axe) > pi/2 + srt <- 180 * XY$axe / pi + srt[adj] <- srt[adj] - 180 + adj <- as.numeric(adj) + xx.tips <- xx[1:Ntip] + yy.tips <- yy[1:Ntip] + if (label.offset) { + xx.tips <- xx.tips + label.offset * cos(XY$axe) + yy.tips <- yy.tips + label.offset * sin(XY$axe) + } ## `srt' takes only a single value, so can't vectorize this: ## (and need to 'elongate' these vectors:) font <- rep(font, length.out = Ntip) tip.color <- rep(tip.color, length.out = Ntip) cex <- rep(cex, length.out = Ntip) for (i in 1:Ntip) - text(xx[i], yy[i], cex = cex[i], x$tip.label[i], adj = adj[i], - font = font[i], srt = srt[i], col = tip.color[i]) + text(xx.tips[i], yy.tips[i], cex = cex[i], + x$tip.label[i], adj = adj[i], font = font[i], + srt = srt[i], col = tip.color[i]) } } if (type %in% c("fan", "radial")) { xx.tips <- xx[1:Ntip] + yy.tips <- yy[1:Ntip] ## using atan2 considerably facilitates things compared to acos... - angle <- atan2(yy[1:Ntip], xx.tips)*180/pi + angle <- atan2(yy.tips, xx.tips) # in radians + if (label.offset) { + xx.tips <- xx.tips + label.offset * cos(angle) + yy.tips <- yy.tips + label.offset * sin(angle) + } s <- xx.tips < 0 + angle <- angle * 180/pi # switch to degrees angle[s] <- angle[s] + 180 - adj <- numeric(Ntip) - adj[xx.tips < 0] <- 1 + adj <- as.numeric(s) ## `srt' takes only a single value, so can't vectorize this: ## (and need to 'elongate' these vectors:) font <- rep(font, length.out = Ntip) tip.color <- rep(tip.color, length.out = Ntip) cex <- rep(cex, length.out = Ntip) for (i in 1:Ntip) - text(xx[i], yy[i], x$tip.label[i], font = font[i], cex = cex[i], - srt = angle[i], adj = adj[i], col = tip.color[i]) + text(xx.tips[i], yy.tips[i], x$tip.label[i], font = font[i], + cex = cex[i], srt = angle[i], adj = adj[i], + col = tip.color[i]) } } if (show.node.label) - text(xx[ROOT:length(xx)] + label.offset, yy[ROOT:length(yy)], - x$node.label, adj = adj, font = font, srt = srt, cex = cex) + text(xx[ROOT:length(xx)] + label.offset, yy[ROOT:length(yy)], + x$node.label, adj = adj, font = font, srt = srt, cex = cex) L <- list(type = type, use.edge.length = use.edge.length, node.pos = node.pos, show.tip.label = show.tip.label, show.node.label = show.node.label, font = font, diff --git a/man/corMartins.Rd b/man/corMartins.Rd index f6f673a..7e27d7c 100644 --- a/man/corMartins.Rd +++ b/man/corMartins.Rd @@ -4,7 +4,7 @@ \alias{corMatrix.corMartins} \title{Martins's (1997) Correlation Structure} \usage{ -corMartins(value, phy, form=~1, fixed = FALSE) +corMartins(value, phy, form = ~1, fixed = FALSE) \method{coef}{corMartins}(object, unconstrained = TRUE, ...) \method{corMatrix}{corMartins}(object, covariate = getCovariate(object), corr = TRUE, ...) diff --git a/man/rotate.Rd b/man/rotate.Rd index 850247a..a901bf8 100644 --- a/man/rotate.Rd +++ b/man/rotate.Rd @@ -39,13 +39,11 @@ nodelabels() tre.new <- rotate(tre, 30) # compare the results: -X11() # open new graphical device par(mfrow=c(1,2)) # devide graphical device plot(tre) # plot old tre plot(tre.new) # plot new tree # visualize labels of terminal nodes: -X11() # open new graphical device plot.phylo(tre) tiplabels() @@ -53,7 +51,6 @@ tiplabels() tre.new <- rotate(tre, c(12, 21)) # compare the results: -X11() # open new graphical device par(mfrow=c(1,2)) # devide graphical device plot(tre) # plot old tre plot(tre.new) # plot new tree @@ -62,7 +59,6 @@ plot(tre.new) # plot new tree tre.new <- rotate(tre, c("t3", "t14")) # compare the results: -X11() # open new graphical device par(mfrow=c(1,2)) # devide graphical device plot(tre) # plot old tre plot(tre.new) # plot new tree diff --git a/man/vcv.phylo.Rd b/man/vcv.phylo.Rd index 702ca63..f48e574 100644 --- a/man/vcv.phylo.Rd +++ b/man/vcv.phylo.Rd @@ -11,7 +11,8 @@ vcv(phy, ...) \arguments{ \item{phy}{an object of the correct class (see above).} \item{model}{a character giving the model used to compute the - variances and covariances; only \code{"Brownian"} is available.} + variances and covariances; only \code{"Brownian"} is available (for + other models, a correlation structure may be used).} \item{corr}{a logical indicating whether the correlation matrix should be returned (\code{TRUE}); by default the variance-covariance matrix is returned (\code{FALSE}).} -- 2.39.2