Skip to content

Commit

Permalink
updates to dotTree to label trait columns
Browse files Browse the repository at this point in the history
  • Loading branch information
liamrevell committed Nov 21, 2018
1 parent 8d462dc commit 60a0f9b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 20 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
@@ -1,6 +1,6 @@
Package: phytools
Version: 0.6-63
Date: 2018-11-9
Version: 0.6-64
Date: 2018-11-21
Title: Phylogenetic Tools for Comparative Biology (and Other Things)
Author: Liam J. Revell
Maintainer: Liam J. Revell <liam.revell@umb.edu>
Expand All @@ -13,6 +13,6 @@ ZipData: no
Description: A wide range of functions for phylogenetic analysis. Functionality is concentrated in phylogenetic comparative biology, but also includes a diverse array of methods for visualizing, manipulating, reading or writing, and even inferring phylogenetic trees and data. Included among the functions in phylogenetic comparative biology are various for ancestral state reconstruction, model-fitting, simulation of phylogenies and data, and multivariate analysis. There are a broad range of plotting methods for phylogenies and comparative data which include, but are not restricted to, methods for mapping trait evolution on trees, for projecting trees into phenotypic space or a geographic map, and for visualizing correlated speciation between trees. Finally, there are a number of functions for reading, writing, analyzing, inferring, simulating, and manipulating phylogenetic trees and comparative data not covered by other packages. For instance, there are functions for randomly or non-randomly attaching species or clades to a phylogeny, for estimating supertrees or consensus phylogenies from a set, for simulating trees and phylogenetic data under a range of models, and for a wide variety of other manipulations and analyses that phylogenetic biologists might find useful in their research.
License: GPL (>= 2)
URL: http://github.com/liamrevell/phytools
Packaged: 2018-11-9 12:00:00 EST
Packaged: 2018-11-21 12:00:00 EST
Repository:
Date/Publication: 2018-11-9 12:00:00 EST
Date/Publication: 2018-11-21 12:00:00 EST
53 changes: 38 additions & 15 deletions R/dotTree.R
@@ -1,5 +1,5 @@
## function to plot a tree with dots/circles for a plotted phenotype
## written by Liam J. Revell 2016, 2017
## written by Liam J. Revell 2016, 2017, 2018

dotTree<-function(tree,x,legend=TRUE,method="plotTree",standardize=FALSE,...){
if(is.data.frame(x)) x<-as.matrix(x)
Expand Down Expand Up @@ -30,7 +30,8 @@ dotTree.continuous<-function(tree,x,color,legend,method,standardize,...){
else x<-x[,1]
}
if(hasArg(fsize)) fsize<-list(...)$fsize
else fsize<-1
else fsize<-c(1,0.8)
if(length(fsize)==1) fsize<-rep(fsize,2)
if(hasArg(x.space)) x.space<-list(...)$x.space
else x.space<-0.1
if(hasArg(k)) k<-list(...)$k
Expand All @@ -50,6 +51,7 @@ dotTree.continuous<-function(tree,x,color,legend,method,standardize,...){
max.x<-max(x)
if(any(x<0)) x<-x-min(x)
if(method=="plotTree"){
fsize<-fsize[1]
x<-x[tree$tip.label]
## plot tree
plotTree(tree,offset=1.7,ylim=c(-Ntip(tree)/25,
Expand All @@ -75,11 +77,18 @@ dotTree.continuous<-function(tree,x,color,legend,method,standardize,...){
} else if(method=="phylogram"){
if(is.vector(x)) x<-as.matrix(x)
x[]<-x[tree$tip.label,]
if(hasArg(mar)) mar<-list(...)$mar
else mar<-rep(0.1,4)
if(hasArg(xlim)) xlim<-list(...)$xlim
else xlim<-c(-0.5,0.55+x.space*ncol(x)+x.space/2)
if(hasArg(labels)) labels<-list(...)$labels
else labels<-FALSE
if(hasArg(ylim)) ylim<-list(...)$ylim
else ylim<-c(if(legend) -0.1 else 0,if(labels) 1.1 else 1)
## plot tree
plot.new()
par(mar=rep(0.1,4))
plot.window(xlim=c(-0.5,0.55+x.space*ncol(x)+x.space/2),
ylim=c(if(legend) -0.1 else 0,1))
par(mar=mar)
plot.window(xlim=xlim,ylim=ylim)
h<-phylogram(tree,...)
## get last phylo plot parameters
obj<-get("last_plot.phylo",envir=.PlotPhyloEnv)
Expand All @@ -88,20 +97,23 @@ dotTree.continuous<-function(tree,x,color,legend,method,standardize,...){
## plot points
rr<-(k*x/max(x)+x.space)/2*diff(par()$usr[1:2])/diff(par()$usr[3:4])/
(Ntip(tree)-1)
if(k<=0.8&&any(rr>(strwidth("W")*fsize/2)))
rr<-rr/max(rr)*strwidth("W")*fsize/2
if(k<=0.8&&any(rr>(strwidth("W")*fsize[1]/2)))
rr<-rr/max(rr)*strwidth("W")*fsize[1]/2
for(i in 1:ncol(x)){
nulo<-mapply(draw.circle,x=x.tip+1.2*strwidth("W")+x.space*(i-1),
y=y.tip,radius=rr[,i],MoreArgs=list(nv=200,col=color))
## draw.circle(x.tip+1.2*strwidth("W")+x.space*(i-1),y.tip,
## nv=200,radius=rr[,i],col=color)
}
## add legend
if(legend){
h<-dot.legend(x=-0.45,y=-0.04,min.x,max.x,Ntip=Ntip(tree),
method="phylogram",...)
if(standardize) text(h,-0.04,"(SD units)",pos=4)
}
if(labels){
text(x=seq(max(x.tip)+1.2*strwidth("W"),
max(x.tip)+1.2*strwidth("W")+x.space*(ncol(x)-1),by=x.space),
y=rep(1.02,ncol(x)),colnames(x),srt=70,adj=c(0,0.5),cex=fsize[2])
}
}
}

Expand All @@ -112,7 +124,8 @@ dotTree.discrete<-function(tree,x,color,legend,method,...){
else x<-x[,1]
}
if(hasArg(fsize)) fsize<-list(...)$fsize
else fsize<-1
else fsize<-c(1,0.8)
if(length(fsize)==1) fsize<-rep(fsize,2)
if(hasArg(x.space)) x.space<-list(...)$x.space
else x.space<-0.1
## reorder tree
Expand Down Expand Up @@ -140,11 +153,18 @@ dotTree.discrete<-function(tree,x,color,legend,method,...){
} else if(method=="phylogram"){
if(is.vector(x)) x<-as.matrix(x)
x[]<-x[tree$tip.label,]
if(hasArg(mar)) mar<-list(...)$mar
else mar<-rep(0.1,4)
if(hasArg(xlim)) xlim<-list(...)$xlim
else xlim<-c(-0.5,0.55+x.space*ncol(x)+x.space/2)
if(hasArg(labels)) labels<-list(...)$labels
else labels<-FALSE
if(hasArg(ylim)) ylim<-list(...)$ylim
else ylim<-c(if(legend) -0.1 else 0,if(labels) 1.1 else 1)
## plot tree
plot.new()
par(mar=rep(0.1,4))
plot.window(xlim=c(-0.5,0.55+x.space*ncol(x)+x.space/2),
ylim=c(if(legend) -0.06 else 0,1))
par(mar=mar)
plot.window(xlim=xlim,ylim=ylim)
h<-phylogram(tree,...)
## get last phylo plot parameters
obj<-get("last_plot.phylo",envir=.PlotPhyloEnv)
Expand All @@ -157,14 +177,17 @@ dotTree.discrete<-function(tree,x,color,legend,method,...){
nulo<-mapply(draw.circle,x=x.tip+1.2*strwidth("W")+x.space*(i-1),
y=y.tip,col=color[as.character(x[,i])],MoreArgs=list(nv=20,
radius=r))
## draw.circle(x.tip+1.2*strwidth("W")+x.space*(i-1),y.tip,
## nv=200,radius=r,col=color[as.character(x[,i])])
}
## add legend
if(legend){
add.simmap.legend(colors=color,prompt=FALSE,
vertical=FALSE,shape="circle",x=-0.45,y=-0.06)
}
if(labels){
text(x=seq(max(x.tip)+1.2*strwidth("W"),
max(x.tip)+1.2*strwidth("W")+x.space*(ncol(x)-1),by=x.space),
y=rep(1.02,ncol(x)),colnames(x),srt=70,adj=c(0,0.5),cex=fsize[2])
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion man/bind.tip.Rd
Expand Up @@ -9,7 +9,7 @@ bind.tip(tree, tip.label, edge.length=NULL, where=NULL, position=0,
\item{tree}{receptor tree.}
\item{tip.label}{a string containing the species name for the new tip.}
\item{edge.length}{edge length for the new tip (a scalar).}
\item{where}{node number to attach new tip. If \code{position>0} then then tip will be attached \emph{below} the specified node. Node numbers can also be tips, in which case the new tip will be added along the terminal edge. To find out the tip number for given species with name \emph{"species"} type: \code{which(tree$tip.label=="species"}.}
\item{where}{node number to attach new tip. If \code{position>0} then then tip will be attached \emph{below} the specified node. Node numbers can also be tips, in which case the new tip will be added along the terminal edge. To find out the tip number for given species with name \emph{"species"} type: \code{which(tree$tip.label=="species")}.}
\item{position}{distance \emph{below} node to add tip.}
\item{interactive}{logical value indicating whether or not the species should be added interactively. (Defaults to \code{FALSE}.)}
\item{...}{arguments to be passed to \code{plotTree} (for \code{interactive=TRUE}.)}
Expand Down

0 comments on commit 60a0f9b

Please sign in to comment.