It took me quite a while to get this working, but I finally did:
The tree topology is from Rüber et al. (2004). This is what I used to generate the image:
animateSimmap = function(phy, interval = .02, numb = length(phy), name = "animation.gif", ...) {
if(class(phy) != "multiPhylo") stop("object must be multiPhylo")
saveGIF(for(i in 1:numb) {
dev.hold()
plotSimmap(phy[[i]], ...)
Sys.sleep(interval)
}, movie.name = name)
}
So this function takes in a multiPhylo object that has stochastic character mappings, the time interval between trees (I'm not sure if this does anything because saveGIF might just have a set interval already), the number of mappings to animate, the name of the file to create, and any arguments you want to give to the plotSimmap function. In terms of the mappings shown above, they're meaningless because the branches aren't proportional to anything meaningful, but it shows how this function would work.
plotSimmap is from the package phytools, and saveGIF is from the package animation. To use saveGIF, you also need either ImageMagick (which is what I used), GraphicsMagick, or LyX.
No comments:
Post a Comment