如何使用 R 将一个大的 igraph 子集化为一个节点及其连接的节点?
How to subset a large igraph to just one node and its connected nodes using R?
我在 R 中有一个非常大的 igraph(称为 g)。
我只对一个节点 (NodeA) 以及任何直接连接到 NodeA 的节点感兴趣。我想得到一个非常简单的图表,如下图所示。
我已经尝试过 subgraph(g, "nodeA") 但我最终只得到了 NodeA。
我想我需要将图 g 的边子集化为连接到节点 A 的边,然后使用 subgraph.edges()。我不知道如何根据边缘连接到的节点对边缘进行子集化...
尝试使用 neighbors()
# Example graph
g1 <- graph_from_literal(1:2:3---3:4:5)
# Let's take a look at it
plot(g1)
# 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)
如果 order=1
: ?make_ego_graph
应该这样做
g <- make_graph(c(1, 2, 2, 3, 3, 4, 5, 6), directed = FALSE)
V(g)$name <- letters[1:6]
g
#IGRAPH UN-- 6 4 --
#+ attr: name (v/c)
#+ edges from 657f0a0 (vertex names):
#[1] a--b b--c c--d e--f
make_ego_graph(g, order=1, nodes=2)
#[[1]]
#IGRAPH UN-- 3 2 --
#+ attr: name (v/c)
#+ edges from 69681da (vertex names):
#[1] a--b b--c
我在 R 中有一个非常大的 igraph(称为 g)。
我只对一个节点 (NodeA) 以及任何直接连接到 NodeA 的节点感兴趣。我想得到一个非常简单的图表,如下图所示。
我已经尝试过 subgraph(g, "nodeA") 但我最终只得到了 NodeA。
我想我需要将图 g 的边子集化为连接到节点 A 的边,然后使用 subgraph.edges()。我不知道如何根据边缘连接到的节点对边缘进行子集化...
尝试使用 neighbors()
# Example graph
g1 <- graph_from_literal(1:2:3---3:4:5)
# Let's take a look at it
plot(g1)
# 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)
order=1
: ?make_ego_graph
应该这样做
g <- make_graph(c(1, 2, 2, 3, 3, 4, 5, 6), directed = FALSE)
V(g)$name <- letters[1:6]
g
#IGRAPH UN-- 6 4 --
#+ attr: name (v/c)
#+ edges from 657f0a0 (vertex names):
#[1] a--b b--c c--d e--f
make_ego_graph(g, order=1, nodes=2)
#[[1]]
#IGRAPH UN-- 3 2 --
#+ attr: name (v/c)
#+ edges from 69681da (vertex names):
#[1] a--b b--c