可视化 igraph 中的许多组件之一

Visualize one out of many components in igraph

使用 R igraph 包,我有一个具有以下边的无向图:

A--BB--CA--CC--DE--F & G--H

plot() 函数绘制了整个网络,但我只想可视化包含节点 A 的连通分量。

您可以使用 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)