I'm trying to order the rows of a dataframe based on the tip labels found in a phylogenetic tree. The way I was going to do this was to use the match
function similar to the answer from this question, however I'm stuck cause the tip.label
property of the ape
phylo object doesn't change if you reorder the nodes using the ladderize
function.
library(ape)
tree <- read.tree(text = "(((A,B),(C,D)),E);")
tree2 <- ladderize(tree, right = FALSE)
tree$tip.label
#> [1] "A" "B" "C" "D" "E"
tree2$tip.label
#> [1] "A" "B" "C" "D" "E"
Notice that the order of the tip.label
hasn't changed even though the visual representation of the tree does. In this simple example the visual order of the tree after the ladderize
function is E A B C D
(reading from bottom to top on the tree after plotting). How can I get a copy of the tip.label
vector where the order reflects the new order of the nodes in the tree?