I would like to draw two graphs g1
and g2
on the same plot with the R
version of igraph
. However, if I just apply the plot
(or plot.igraph
) function twice, I just get two separate plots. Is there a way to have both graphs drawn on the same plot?
Here's some minimal code:
library(igraph)
g1 <- barabasi.game(10)
g2 <- barabasi.game(5)
plot(g1)
plot(g2)
Edit: I want both graphs to be plotted in the same figure. So, one node from g1
and another one from g2
could very well overlap in this figure, if they hold close spatial positions in their respective graphs.
Try this:
library(igraph)
g1 <- barabasi.game(10)
g2 <- barabasi.game(5)
plot(g1)
plot(g2, edge.color='black', vertex.color='green', add=T)
The main trick here is to use add=TRUE
while plotting the second graph.
I have changed the color of edges and vertices of g2 to be able to tell g2 apart from g1.
we can use par(mfrow=c(1,2)), and write add=TRUE in 2nd plot.
library(igraph)
par(mfrow=c(1,2))
g1 <- barabasi.game(10)
g2 <- barabasi.game(5)
plot(g1)
plot(g2,add=TRUE)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With