I have some simple tree-like edge-data (e.g. data below) with the following characteristics:
- there is a root node (
0
) - all non-root nodes have exactly one parent, but 0-to-many children (including 1)
- there is a time
t
associated with each edge (or equivalently each unique node ini.fr
) - we can compute
dt
as below, if helpful
I want to plot these data as a tree, with time along one dimension, so that edge lengths are proportional to dt
(e.g. sketch below). How can I do this in R?
I explored ape
and data.tree
packages, and ggtree
, but none seem to provide interface for creating tree objects from edge lists, and I think my data (with 1-child nodes) are rejected as some types of trees?
Sample Data
tree = data.frame(
t = c( 0, 1, 1, 4, 5, 7),
i.fr = c( 0, 1, 1, 2, 3, 5),
i.to = c( 1, 2, 3, 4, 5, 6),
dt = c(NA, 1, 1, 3, 4, 2))
Fake phylo
fake.phylo = list(
edge = cbind(tree$i.fr,tree$i.to),
tip.label = c('4','6'),
Nnode = 5,
edge.length = tree$dt)
class(fake.phylo) = 'phylo'
phylo.tree = as.phylo(fake.phylo) # works