Thursday, May 23, 2013

Plotting a circular discrete character mapped tree, part II: The colors

Now that we've figured out how to plot the structure of a circular (i.e., "fan") tree, the next step is segmenting our plotted edges by a discrete character & then plotting segment by color. Here's my function for this next step. Note that (again) this depends on the package 'plotrix' and will not work if there is no character mapped on the tree:

  if(!require(plotrix)) stop("install 'plotrix'")
  # check colors
      cat("no colors provided. ")
      cat("using the following legend:\n")
  # reorder
  # count nodes and tips
  # get Y coordinates on uncurved space
  for(i in 1:m){
  # now put into a circular coordinate system
  # plot nodes
  # plot radial lines (edges)
  for(i in 1:nrow(cw$edge)){
    for(i in 1:(length(xx)-1))
  # plot circular lines
  for(i in 1:m+n){

The key attributes that I've added is segmentalization of each edge by the mapped state, and then separate plotting of each edge segment according to the colors for the state.

Let's try it out:

> Q<-matrix(c(-1,1,1,-1),2,2)
> rownames(Q)<-colnames(Q)<-letters[1:2]
> Q
   a  b
a -1  1
b  1 -1
> tree<-sim.history(tree,Q)
> plotSimmap(tree,colors=setNames(c("blue","red"), letters[1:2]))
> source("plotFan.R")
> plotFan(tree,colors=setNames(c("blue","red"), letters[1:2]))

Cool. Now we just need to clean it up a bit & add labels....

No comments:

Post a Comment

Note: due to the very large amount of spam, all comments are now automatically submitted for moderation.