我在 R 中有一个非常大的 igraph(称为 g)。
我只对一个节点 (NodeA) 以及直接连接到 NodeA 的任何节点感兴趣。我想最终得到一个非常简单的图表,如下图所示。
我试过 subgraph(g, "nodeA") 但我最终只得到了 NodeA。
我想我需要将图 g 的边子集到连接到 nodeA 的边,然后使用 subgraph.edges()。我无法弄清楚如何根据边缘连接到的节点对边缘进行子集化...
尝试使用neighbors()
# Example graph
g1 <- graph_from_literal(1:2:3---3:4:5)
# Let's take a look at it
plot(g1)
Run Code Online (Sandbox Code Playgroud)
# Say we are interested in the subgraph consisting of vertex 1 and all
# other vertices it is connected to
g2 <- induced_subgraph(g1, c(1, neighbors(g1,1)))
plot(g2)
Run Code Online (Sandbox Code Playgroud)