r - How to change id of nodes in igraph? -


i have tree such as:

library(igraph) tree<- graph.empty(15) tree <- tree + path(5,4,3,1,2) tree <- tree + path(8,7,6,5) tree <- tree + path(15,14,13,12,11,10,9,5)  root <- v(tree)[igraph::degree(tree, mode="out")==0] plot(tree, vertex.size=6, edge.arrow.size=0.1,       layout=layout.reingold.tilford(tree, mode="in", root=root)) 

vertex ids given input order:

v(tree) vertex sequence:  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 

enter image description here

i re-number ids root 1. using name attribute get:

# label root 1, , rest 2...n root <- v(tree)[igraph::degree(tree, mode="out")==0] v(tree)$name[v(tree) != root] <- 2:vcount(tree) v(tree)$name[v(tree) == root] <- 1 root <- v(tree)[igraph::degree(tree, mode="out")==0] plot(tree, vertex.size=6, edge.arrow.size=0.1,      layout=layout.reingold.tilford(tree, mode="in", root=root)) 

enter image description here

but ids unchanged:

v(tree) vertex sequence:  [1]  2  1  3  4  5  6  7  8  9 10 11 12 13 14 15  v(tree)$name  [1]  2  1  3  4  5  6  7  8  9 10 11 12 13 14 15 

is there way re-assign ids can directly play them instead of names? should give:

v(tree) vertex sequence:  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -