[英]R: Split a graph into several graphs
This graph contains 4 communities. 该图包含4个社区。
I want to convert each community to a new graph. 我想将每个社区转换为一个新图形。 How should I do this?
我应该怎么做?
Since you do not provide data, I will use a simplified version of your graph to illustrate. 由于您不提供数据,因此我将使用图形的简化版本进行说明。
## Example graph
library(igraph)
g <- graph_from_literal(1-2-3-4-1, 2-5-4,
2-6, 6-7-10-8-6, 6-9-10)
CL = cluster_louvain(g)
plot(CL, g)
In order to graph the individual communities, you can use induced_subgraph
to get the subgraphs and then use the like any other graph, including plotting them. 为了绘制各个社区的图,您可以使用
induced_subgraph
子图来获取子图,然后像其他任何图一样使用它,包括对其进行绘制。
## Get graphs for each community
C1 = induced_subgraph(g, which(membership(CL) == 1))
C2 = induced_subgraph(g, which(membership(CL) == 2))
plot(C1)
plot(C2)
Note: I combined the graphs by hand. 注意:我手动组合了图。 They were printed separately.
它们分别打印。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.