I have a rooted forest with 116 trees as a tidygraph
object. I now want to add a new property to the nodes, i.e. label the nodes within the branches.
For instance, for a graph
a <- tibble(from = c(1, 2, 3, 3, 4, 5, 7, 8, 8, 9, 10),
to = c(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12))
a_graph = as_tbl_graph(a)
I'd like to have a column in the node data with c("A", "A", "A", "B", "C", "B", "C", "C", "D", "E", "D", "E")
, i.e. nodes 1-3 are labeled with A, nodes 4 and 6 with B, nodes 5, 7, 8 with C, nodes 9 and 11 with D, and nodes 10 and 12 with E.
So, is there a way to automatically label the nodes depending on the branch they're on even if the trees in my forest can have very different structures?