A little while ago, I updated plotSimmap(...,type="phylogram") to (optionally) set the environmental variable "last_plot.phylo" in the environment .PlotEnvPhylo. This has the effect of making plotSimmap fully compatible with nodelabels, tiplabels, edgelabels, and (now) add.scale.bar from the ape package.
The latest version of plotSimmap includes two important updates: (1) now setting the environmental variable "last_plot.phylo", though still optional, defaults to setEnv=TRUE; and (2) setEnv works for both type="phylogram" and type="fan". Since the latter is new - let's try a quick demo showing a stochastic of 'ecomorph' on the tree of Caribbean Anolis ecomorph species, with posterior probabilities from stochastic mapping at internal nodes overlain:
> require(phytools)
Loading required package: phytools
> packageVersion("phytools")
[1] ‘0.3.38’
> # load anole 'ecomorph' tree
> data(anoletree)
> # this is a stochastic mapped tree - pull tip states
> x<-getStates(anoletree,"tips")
> # conduct stochastic mapping
> trees<-make.simmap(anoletree,x,model="ER",nsim=100, message=FALSE)
> # get the states at ancestral nodes
> aa<-describe.simmap(trees,plot=FALSE)
100 trees with a mapped discrete character with states:
CG, GB, TC, TG, Tr, Tw
trees have 25.79 changes between states on average
changes are of the following types:
...
> # set colors to be used for mapping
> cols<-setNames(palette()[1:6],sort(unique(x)))
> # plotSimmap
> plotSimmap(trees[[1]],cols,type="fan",lwd=3,fsize=0.7)
setEnv=TRUE for this type is experimental. please be patient with bugs
> # add node labels
> nodelabels(pie=aa$ace,piecol=cols,cex=0.4)
> # add legend
> add.simmap.legend(colors=cols,fsize=0.8)
Click where you want to draw the legend
This update is in a new phytools build (phytools 0.3-38).
Hi Liam,
ReplyDeleteI try to run this analysis, however the program throws me the following error: Error in make.simmap (tree, states, nsim = 1000, message = FALSE):
subscript out of bounds.
If you could guide me to solve this problem I would be very grateful
P. D. a small query, the species may have been more of a character state?