I have a connected component in a graph and I need to convert it into a data frame. Each vertex should be assigned a unique label based on its position or path within the graph. For instance, vertices A1 to A3 should share the label A, and vertices C1 to C3 should share the label C. The criteria for labelling is that the path terminates either before a vertex with two incoming edges or at a vertex with two outgoing edges. The images also the expected number of labels, i.e., 7.
A reproducible example:
library(igraph)
df <- structure(list(from = c("A1", "A2", "A3", "A4", "B1", "B2", "B3",
"C1", "C2", "C3", "E1", "E2", "E3", "F1", "F2", "D1", "E3", "G1",
"G2", "G3"), to = c("A2", "A3", "A4", "C1", "B2", "B3", "C1",
"C2", "C3", "D1", "E2", "E3", "F1", "F2", "D1", "D2", "G1", "G2",
"G3", "G4")), class = "data.frame", row.names = c(NA, -20L))
g <- graph_from_data_frame(df)
plot(g)
I thought about using degree
and counting the edges for each vertex. However, I still don’t know the paths (I’m newbie to using igraph).