set.seed(1)
## Generate a random ultrametric tree
tree <- rtree(20)
## Add some node labels
tree$node.label <- letters[1:19]
## Add its root time
tree$root.time <- max(tree.age(tree)$ages)
## Slice the tree at age 1.5
tree_slice <- slice.tree(tree, age = 1.5, "deltran")
## The slice at age 0.5 but keeping all the ancestors
deep_slice <- slice.tree(tree, age = 0.5, "deltran",
keep.all.ancestors = TRUE)
## Visualising the trees
old_par <- par(mfrow = c(2,2))
plot(ladderize(tree), main = "full tree"); axisPhylo()
abline(v = tree$root.time - 1.5)
plot(ladderize(tree_slice), main = "tree slice"); axisPhylo()
plot(ladderize(deep_slice), main = "slice with ancestors"); axisPhylo()
par(old_par)
Run the code above in your browser using DataLab