Careful inspection of your data is a necessary pre-requisite for any phylogenetic analyses. One of the best ways to inspect your data prior to conducting phylogenetic analyses is to visualize your data on your tree(s). Such visualizations can be key to identifying interesting research questions. Gaining an intuitive and visual appreciation for the patterns in your data can also be key to determining if the outcomes of your analyses are sensible. The best available option for visualizing data on phylogenetic trees is the R statistical computing framework. R offers remarkably flexible plotting options that permit visualization of a wide range of data formats and types.
The figure to the left is from Price et al. (2012) and illustrates reef specialization in haemulid fish. The figure on the right will be generated from the same data using this tutorial.
#Tutorial on visualization of character data on phylogenetic trees in R.
lapply(haemulidTreesLadderized, rescale, "depth", 1) -> haemulidTreesLadderized1 #Use the lapply and rescale functions to rescale all 500 of our trees to have a root to tip distance of 1. This rescaling will make subsequent plotting functions somewhat easier. Even more importantly, it will often improve the performance of likelihood functions.
read.csv("haemulidDryadData.csv") -> haemulidDataInput #Load character data for haemulids. This file includes only a subset of the full dataset available via Dryad. Saved in comma delimited text format, this input file should include six columns with taxonomic, habitat, morphological and functional data: genus, species, habitat (reef or non-reef), standard length, raker length, and suction index.
data.frame(haemulidDataInput[,3:6]) -> haemulidData #Convert the habitat, phenotypic, and functional data into a dataframe in R. Dataframes are helpful in R because they store each column of a matrix as a separate object, which will make them easier to call later.
paste(haemulidDataInput[,1], haemulidDataInput[,2], sep="_", collapse=NULL) -> rownames(haemulidData) #Use the paste function to combine the genus and species names in columns 1 and 2 of our data table. The purpose of doing this is to obtain row names for our table that correspond with the names of taxa in our phylogenetic tree, where OTUs are designated as genus_species.
name.check(haemulidTreesLadderized1[], haemulidData) #Use the name.check function of geiger to test if the same taxa are found in the phylogenetic tree and the dataset. You should see that many taxa differ between the two datasets, many apparently due to typographical errors.
tiplabels(cex=0.5) #You should now see that the sequence of taxon labels in your tree object corresponds with the sequence of taxon labels in your plot.
haemulidHabitatLabel hasn’t been defined yet.
May be you can make a repository and put all the related files. Thanks.