Matt.

Here is the same thing with a worked example: http://blog.phytools.org/2014/05/plotting-bars-at-tips-of-circular-tree.html.

Obviously, trait values cannot be negative. (Well, they can be - but it will look very strange.)

I left off the tip labels & other features, but it would be straightforward to modify this so that tip labels are included, or so that a stochastic map (instead of a standard tree) was plotted.

Let me know if this does what you want it to, or if you have any problems.

All the best, Liam

Liam J. Revell, Assistant Professor of Biology
University of Massachusetts Boston
web: http://faculty.umb.edu/liam.revell/
email: liam.rev...@umb.edu
blog: http://blog.phytools.org

On 5/14/2014 11:59 AM, Liam J. Revell wrote:
Hi Matt.

How about the attached example? I did this by writing the following
function:

plotFan.wBars<-function(tree,x,scale=1,width=NULL){
   lims=c(-max(nodeHeights(tree))-scale*max(x),
     max(nodeHeights(tree))+scale*max(x))
   obj<-plotTree(tree,type="fan",ftype="off",xlim=lims,ylim=lims)
   if(is.null(width)) width<-(par()$usr[2]-par()$usr[1])/100
   w<-width
   x<-x[tree$tip.label]*scale
   for(i in 1:length(x)){
     dx<-obj$xx[i]
     dy<-obj$yy[i]
     theta<-atan(dy/dx)
     x1<-dx+(w/2)*cos(pi/2-theta)
     y1<-dy-(w/2)*sin(pi/2-theta)
     x2<-dx-(w/2)*cos(pi/2-theta)
     y2<-dy+(w/2)*sin(pi/2-theta)
     s<-if(dx>0) 1 else -1
     x3<-s*x[i]*cos(theta)+x2
     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")
   }
   invisible(obj)
}

This could probably be done more elegantly, but this seems to work. Let
me know if this is what you had in mind. I will also post this to my blog.

All the best, Liam

Liam J. Revell, Assistant Professor of Biology
University of Massachusetts Boston
web: http://faculty.umb.edu/liam.revell/
email: liam.rev...@umb.edu
blog: http://blog.phytools.org

On 5/14/2014 10:44 AM, Matthew Helmus wrote:
Hi all,

Does anyone know of R code (or perhaps another program) to plot bars
across
the tips of a radial/fan phylogeny?

Specifically, I have a large phylogeny and a corresponding vector of
continuous trait values for the tips, and while I could use those
values to
vary the color and size of the tip labels, or also to plot points of
varying color or size at those tips, I think a better depiction of the
data
would be to plot bars that vary in height.

Thanks!!
Matt

    [[alternative HTML version deleted]]

_______________________________________________
R-sig-phylo mailing list - R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
Searchable archive at
http://www.mail-archive.com/r-sig-phylo@r-project.org/



_______________________________________________
R-sig-phylo mailing list - R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/


_______________________________________________
R-sig-phylo mailing list - R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/

Reply via email to