library(ape) library(geiger) library(ade4) library(picante) library(phytools) # load tree produced by MrBayes tree<-read.nexus("minnows.tre") # get a list of outgroup taxa outgroup<-c("Moxostoma_duquesnii","Moxostoma_erythrurum","Moxostoma_macrolepidotum") # root the tree based on one of the outgroup species rooted_tree<-root(tree,outgroup[1]) # drop the outgroup species rooted_tree<-drop.tip(rooted_tree,outgroup) # plot tree plot.phylo(rooted_tree) # Read the trait data, we are interested in the "eggs" column which has egg size traits<-read.csv("minnow_data.csv",sep=",", header=T,row.names="species") # sort traits frame to match tree traits<-traits[match(rooted_tree$tip.label[],row.names(traits)),] # Make a pretty picture. Map egg size onto the phylogeny egg_size<-as.numeric(traits$egg) names(egg_size)<-row.names(traits) contMap(rooted_tree,egg_size) habitat<-factor(traits$habitat) names(habitat)<-row.names(traits)