r - Plot two igraph networks using the same coordinates and same placement in the plot frame -
i trying plot network changes in time. network starts number of nodes , edges , each time step of nodes , edges removed.
i want able plot network nodes in same place in each. when try this. nodes shift position in plot frame if relation each other same.
i making network change gif small changes annoying. think change may occur when large fraction of nodes removed not sure.
the code below illustrates using er graph.
library(igraph); library(dplyr) #generate random graph set.seed(500) randomgraph <- sample_gnm(1000, 2500) #name nodes v(randomgraph)$name <- paste0("node", 1:1000) #get coordinates of nodes coords <- layout_with_fr(randomgraph) %>% as_tibble %>% bind_cols(data_frame(names = names(v(randomgraph)))) #delete random vertices deletevertex <-sample( v(randomgraph)$name, 400) randomgraph2 <-delete.vertices(randomgraph, deletevertex) #get coordinates of remaining nodes netcoords <- data_frame(names = names(v(randomgraph2))) %>% left_join(coords, by= "names") #plot both graphs randomgraph%>% plot(.,vertex.size=.8, edge.arrow.size=.4, vertex.label = na, layout = as.matrix(coords[,1:2])) randomgraph2%>% plot(.,vertex.size=.8, edge.arrow.size=.4, vertex.label = na, layout = as.matrix(netcoords[,2:3])) #they nodes have same relationship each other not laid out in same position in frame
as can see plots have placed nodes in same place relative each other not relative frame.
how can have plot position fixed.
plot.igraph rescales each axis default (from -1 +1 on both x , y).
you need turn off: rescale = f
, explicitly set appropriate xlim
, ylim
values.
for example code..
randomgraph%>% plot(.,vertex.size=.8, edge.arrow.size=.4, vertex.label = na, layout = as.matrix(coords[,1:2]),rescale=f,xlim=c(-25,30),ylim=c(-20,35)) randomgraph2%>% plot(.,vertex.size=.8, edge.arrow.size=.4, vertex.label = na, layout = as.matrix(netcoords[,2:3]),rescale=f,xlim=c(-25,30),ylim=c(-20,35))
Comments
Post a Comment