Examples from Chapter 9, Beyond Mk

Read in data

Read in data from Gomez-Mestre et al. 2012 Evolution.

fData<-read.table(text=getURL("https://raw.githubusercontent.com/lukejharmon/pcm/master/datafiles/frogDISCRETE.txt"), header=T)

fDiscrete<-fData[,-1]
rownames(fDiscrete)<-fData[,1]

fTree<-read.tree(text=getURL("https://raw.githubusercontent.com/lukejharmon/pcm/master/datafiles/frog720jjw.phy"))
fTree <-read.tree(text=write.tree(fTree))
plot(fTree)

Ancestral state reconstruction

Make and plot an ancestral state reconstruction.

h1Data<-fDiscrete[,1]
names(h1Data)<-rownames(fDiscrete)

aa<-rerootingMethod(fTree, h1Data, model="ER")

plot(fTree,no.margin=TRUE,edge.width=2, show.tip.label=FALSE)

nodelabels(pie=aa$marginal.anc,piecol=palette()[1:4], cex=0.3)


mm<-match(fTree$tip.label, names(h1Data))
tiplabels(pie=to.matrix(h1Data[mm],colnames(aa$marginal.anc)), piecol=palette()[1:4],cex=0.1)


add.simmap.legend(leg=c("aquatic eggs", "terrestrial eggs", "direct development"), colors=c("black", "red", "green"), x=0.024, y =23, prompt=F)