How to remove vertex from igraph without changing locations

I have a graph g containing 100 vertices, I want to remove the number of vertices from this graph to get g1, but when I do this, I want the positions of each vertex in g to be preserved. Can this be done?

par(mfrow=c(1,2))
g <- erdos.renyi.game(100, 1/100)
comps <- clusters(g)$membership
colbar <- rainbow(max(comps)+1)
V(g)$color <- colbar[comps+1]
V(g)$size<-seq(0.05,5,0.05)
plot(g, layout=layout.fruchterman.reingold, vertex.label=NA)

g1<-g - c("1","2","7","10")
plot(g1, layout=layout.fruchterman.reingold, vertex.label=NA)

The work that I was thinking about would paint for me white peaks and edges that I no longer want to see, but before embarking on this route, I was wondering if there was anything that was less to crack.

+4
source share
2 answers

You can save layout layouts from the graph g:

locs <- layout.fruchterman.reingold(g)
plot(g, layout=locs, vertex.label=NA)

enter image description here

Then you can reuse them in the build g1by deleting places for the remote nodes:

g1<-g - c("1","2","7","10")
plot(g1, layout=locs[-c(1, 2, 7, 10),], vertex.label=NA)

enter image description here

+6

x y, .

locs <- layout_with_fr(g)
V(g)$x <- locs[, 1]
V(g)$y <- locs[, 2]
g1 <- delete_vertices(g, c(1, 2, 7, 10))
plot(g1, vertex.label=NA)

, layout .

+2

All Articles