Occasionally when performing phylogenetic analyses, one will acquire phylogenetic data from a third-party source. In this case, the data represented in that phylogeny may or may not include the exact same species for which you have landmark data.
Here we describe a relatively easy way to compare and adjust
phylogenetic trees to match input landmark data with taxonomic
information, using the function treedata found in the R
package geiger.
treedata() (Expand for more details)
phy.The data “plethspecies” embedded in geomorph includes
both landmark data, and a phylogenetic tree. Crucially, one’s landmark
data must include species name information (see Array tutorial for more
detail).
The treedata function requires two components. First, an
object of class “phylo,” and second, landmark data with species name
information. Importantly, for the treedata function to
work, all landmark coordinates must be arranged by row. In other words,
all landmark coordinates for a single specimen will be contained in a
single row, with the row name being the species name, like so:
ex <- matrix(rep(1, 50), ncol = 10)
colnames(ex)<- c("X1","Y1","X2","Y2","X3","Y3","X4","Y4","X5","Y5")
rownames(ex)<- c("Species A", "Species A", "Species B", "Species C", "Species D")
ex
## X1 Y1 X2 Y2 X3 Y3 X4 Y4 X5 Y5
## Species A 1 1 1 1 1 1 1 1 1 1
## Species A 1 1 1 1 1 1 1 1 1 1
## Species B 1 1 1 1 1 1 1 1 1 1
## Species C 1 1 1 1 1 1 1 1 1 1
## Species D 1 1 1 1 1 1 1 1 1 1
Many functions in geomorph require one’s data be in 3D
array format. Likewise, the read.tps function imports landmark in 3D
array format automatically. While this is useful for using geomorph, a
3D array cannot be used with the treedata function, because an array
does not have row names in the same way that a simple matrix does.
Therefore, 3D arrays will need to be converted into a format that can
be read by treedata. Luckily there is a function in
geomorph that does this! Below we show the use of the
two.d.array function to convert a 3D array of landmarks to
a format that can be read by treedata:
treematch <- treedata(pleth$phy, two.d.array(pleth$land), sort = TRUE)
pleth$phy <- arrayspecs(treematch$data, 11, 2)
After treedata has run, one can simply restore the landmark data to its previous format using the arrayspecs function.