0
votes

I have an adjacency matrix10x10, I use graph.adjacency(matrix) from igraph library and I plot the graph. Now, I want to update the plot and add some edges from another matrix10x10. I need a function like points or lines that can draw new edges on the existing plot with an edge list or with a new adjacency matrix. thanks in advance and sorry for my bad english

library(igraph)

g<-barabasi.game(p,directed=F)

m<-as.matrix(get.adjacency(g)) # example of main matrix

plot(graph.adjacency(m,mode="undirected"))

1
Please add a minimally reproducible example and whatever code you have so farmlegge
The easiest thing might be to add the two adjacency matrices to create a new graph and plot it again, but the layout (where the nodes are) might be different. Does plot for graph objects let you do "add=TRUE" to overlay things?Spacedman

1 Answers

1
votes

The easiest would be to re-plot. You could save the layout coordinates like this:

library(igraph)
set.seed(1)
m <- as.matrix(get.adjacency(barabasi.game(10,directed=F))) # example of main matrix
g <- graph.adjacency(m, mode="undirected")
coords <- layout.fruchterman.reingold(g)
par(mfrow = c(1, 2))
plot.igraph(g, layout = coords)
plot.igraph(g + edge(3, 9), layout = coords)

enter image description here