简体   繁体   English

用 R igraph 绘制多个图形

[英]Plot several graphs with R igraph

I would like to draw two graphs g1 and g2 on the same plot with the R version of igraph .我想用igraphR版本在同一个图上绘制两个图g1g2 However, if I just apply the plot (or plot.igraph ) function twice, I just get two separate plots.但是,如果我只应用plot (或plot.igraph )函数两次,我只会得到两个单独的图。 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.因此,如果g1一个节点和g2另一个节点在该图中很可能重叠,如果它们在各自的图中保持接近的空间位置。

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.这里的主要技巧是在绘制第二个图形时使用add=TRUE

I have changed the color of edges and vertices of g2 to be able to tell g2 apart from g1 .我已经更改了g2的边缘和顶点的颜色,以便能够将g2g1 区分开来。

we can use par(mfrow=c(1,2)), and write add=TRUE in 2nd plot.我们可以使用 par(mfrow=c(1,2)),并在第二个图中写 add=TRUE。

          library(igraph)
          par(mfrow=c(1,2))
          g1 <- barabasi.game(10)
        g2 <- barabasi.game(5)
          plot(g1)
          plot(g2,add=TRUE)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM