Newick format typically excludes spaces within species & node labels on the tree; however we would often like to plot binomial species names with a space between them. This is done by default in ape's plot.phylo if the "_" character is used in lieu of a space. For instance:
This does not work with phytools functions plotTree and plotSimmap, in which the whole string is written. However, there is no constraint on "phylo" objects in R requiring that tip labels lack spaces, so we can add them if we want before plotting.
> tree$tip.label<-gsub("_"," ",tree$tip.label)
For fun, let's paint the Puerto Rican Anolis ecomorphs on the tree - arbitrarily assigning the stem branches to the state of the descendant node, and the root state to "TG" (i.e., the trunk-ground ecomorph):
> tree<-paintSubTree(tree,which(tree$tip.label=="Anolis occultus"), "Tw",stem=T)
> tree<-paintSubTree(tree,which(tree$tip.label=="Anolis cuvieri"), "CG",stem=T)
> tree<-paintSubTree(tree,which(tree$tip.label=="Anolis poncensis"), "GB",stem=T)
Of course, we can also go back if we want to write the tree to file:ReplyDelete
write.tree(tree,file="treefile.tre") # or
Couldn't you just make the gsub() line internal to plotTree, right before the actual plotting the labels takes place? It seems like, from a programming point of view, that might be the safest course of action as people would then not be at risk of changing their tree object just to plot it and then forgetting this later in an analytical procedure.ReplyDelete
(This of course assumes that no one, ever, would want to plot underscores in tip labels. I would bet cash against the possibility, though.)
Either way, thanks for the tip! I had never played around with gsub() or any of the string manipulation functions much before.
PS: I have a library up on CRAN too now! :)
Yes, that sounds like a good idea. Maybe I will put that into the next version of plotSimmap (and phytools).ReplyDelete
Why don't you post a link to your package so we can check it out.
Sure thing, Liam!ReplyDelete
My package is paleotree and it is focused on offering useful functions for paleontological data, particularly when phylogenetic approaches are used in the fossil record. Although there are a number of functions with miscellaneous uses, it focuses on four things: (1) estimating sampling rates from taxonomic ranges in the fossil record, (2) simulating taxon ranges and converting ranges into a phylogeny, (3) time-scaling cladograms of fossil taxa and (4) plotting diversity curves from fossil data in a way that is comparable to lineage diversity curves from phylogenies.
using plot. phylo command, tree size is bigger and some labels also get cut. how to reduce the size. is there anything like fan.size=0.5 ...ReplyDelete