问题
I'm working with random graphs where the label of nodes are numbers from 1 to N. In my work, I'm deleting some nodes from the graph. My problem is that in R, after deleting is just renaming the nodes again from 1 to remaining N, how I can preserve the label of nodes after deleting ?? thanks a lot
回答1:
If there is no name for a node, the node ID (number) is used to label the graph. To preserve the label, set the name of the nodes to their IDs before removing nodes. Here is a small example.
library(igraph)
set.seed(1234)
g = erdos.renyi.game(10, 0.35)
plot(g)
for(i in 1:vcount(g)) {
V(g)[i]$name = i }
g2 = delete_vertices(g, c(3,8))
plot(g2)
Note that the old labels are preserved.
来源:https://stackoverflow.com/questions/60318302/nodes-labels-after-deleting-in-r