To share yesterday’s blog post, I published the following tweet:
Fitting the Mk model & reconstructing ancestral states when some conditions of the character are not observed among tip species using #Rstats #phytools: https://t.co/1lbmZweMP1. pic.twitter.com/qdOR3A4qTe
— Liam Revell (@phytools_liam) May 31, 2024
The figure of the tweet (with the embeded Mk model visualization) does not actually appear in my post.
As an addendum for posteriority & for interest, here is how that figure was created.
library(phytools)
tree
is a "phylo"
object, x
is a factor vector, anc_ordered
is a marginal ancestral state reconstruction from phytools::ancr
, and fit_ordered
is a fitting model object from phytools::fitMk
.
plotFanTree.wTraits(tree,data.frame(factor(x,levels=0:9)),
part=0.5,colors=list(setNames(hcl.colors(n=10),0:9)),
ftype="off",arc_height=2)
par(fg="transparent")
nodelabels(pie=anc_ordered$ace,piecol=hcl.colors(n=10),
cex=apply(anc_ordered$ace,1,
function(x) if(max(x)<0.9) 0.4 else 0.2))
par(fg="black")
obj<-plot(fit_ordered,add=TRUE,show.zeros=FALSE,
xlim=c(-1,1),ylim=c(-1,2.5),text=FALSE)
points(obj$x,obj$y,pch=16,col=hcl.colors(10),cex=2.7)
text(obj$x,obj$y,0:9,col="white")
That’s all!
how about a fixed-rates continuous-time Markov model (Mk model)?
ReplyDelete