Permalink
Browse files

add control of bar colors to plotTree.wBars

  • Loading branch information...
liamrevell committed Oct 25, 2015
1 parent 3ec59ac commit a5e00c52ab6647f5e52a10ef9d430e73f7002f26
Showing with 8 additions and 3 deletions.
  1. +8 −3 R/plotTree.wBars.R
View
@@ -1,7 +1,8 @@
## function to plot bars at the tips of a plotted tree
## written by Liam J. Revell 2014, 2015
plotTree.wBars<-function(tree,x,scale=1,width=NULL,type="phylogram",method="plotTree",tip.labels=FALSE,...){
plotTree.wBars<-function(tree,x,scale=1,width=NULL,type="phylogram",method="plotTree",tip.labels=FALSE,
col="grey",border=NULL,...){
if(!inherits(tree,"phylo")) stop("tree should be an object of class \"phylo\".")
d<-scale*(max(x)-min(0,min(x)))
H<-nodeHeights(tree)
@@ -36,6 +37,9 @@ plotTree.wBars<-function(tree,x,scale=1,width=NULL,type="phylogram",method="plot
width<-if(type=="fan") (par()$usr[4]-par()$usr[3])/(max(c(max(x)/max(nodeHeights(tree)),1))*length(tree$tip.label))
else if(type=="phylogram") (par()$usr[4]-par()$usr[3])/(2*length(tree$tip.label))
w<-width
if(length(col)<Ntip(tree)) col<-rep(col,ceiling(Ntip(tree)/length(col)))[1:Ntip(tree)]
if(is.null(names(col))) names(col)<-tree$tip.label
col<-col[tree$tip.label]
if(type=="phylogram"){
if(hasArg(direction)) direction<-list(...)$direction
else direction<-"rightwards"
@@ -48,7 +52,7 @@ plotTree.wBars<-function(tree,x,scale=1,width=NULL,type="phylogram",method="plot
y1<-y4<-dy-w/2
y2<-y3<-dy+w/2
polygon(c(x1,x2,x3,x4)-min(0,min(x)),
c(y1,y2,y3,y4),col="grey")
c(y1,y2,y3,y4),col=col[i],border=border)
}
} else if(type=="fan"){
if(min(x)<0) h<-max(nodeHeights(tree))
@@ -71,7 +75,8 @@ plotTree.wBars<-function(tree,x,scale=1,width=NULL,type="phylogram",method="plot
y3<-s*x[i]*sin(theta)+y2
x4<-s*x[i]*cos(theta)+x1
y4<-s*x[i]*sin(theta)+y1
polygon(c(x1,x2,x3,x4),c(y1,y2,y3,y4),col="grey")
polygon(c(x1,x2,x3,x4),c(y1,y2,y3,y4),col=col[i],
border=border)
}
}
invisible(obj)

0 comments on commit a5e00c5

Please sign in to comment.