#R CODE FOR CREATING TRILOBITE CLADOGRAM #STEP 1: Loading required packages install.packages("phangorn") #only run this the first time you start this code library(phangorn) #run this every time you start RStudio #END OF STEP 1 #STEP 2: Reading data files trilo<-read.nexus.data("http://people.ucsc.edu/~mclapham/earth101/data/trilo.nex") trilo_matrix<-read.csv("http://people.ucsc.edu/~mclapham/earth101/data/trilo_matrix.csv",row.names=1) #END OF STEP 2 #STEP 3: Creates phylogeny and optimizes tree based on parsimony trilo_phylo<-phyDat(trilo,type="USER",levels=c("0","1","2")) start_tree<-as.phylo(hclust(dist(trilo_matrix),method="single")) ptree<-optim.parsimony(start_tree,trilo_phylo) ptree_res<-multi2di(ptree,random=F) #END OF STEP 3 #STEP 4: plots cladogram plot(ptree_res) #END OF STEP 4