您可以使用components
来计算组件,使用induced_subgraph
来抓取A组件中的节点:
plot(induced_subgraph(G, with(components(G), membership == membership["A"])))
数据:
library(igraph)
G <- graph.data.frame(data.frame(X=c("A", "B", "A", "C", "E", "G"),
Y=c("B", "C", "C", "D", "F", "H")),
directed=F)