简体   繁体   中英

R: Split a graph into several graphs

This graph contains 4 communities.

这个图

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.

## 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.

社区

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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