R Igraph子图给定节点索引和要包含在图中的节点数

R Igraph subgraph given node index and number of nodes to include in the graph

我想根据特定节点绘制图的一部分,理想情况下是与该节点的距离或作为子图一部分的多个节点。

我绘制的data.frame如下:

Column 1   Column 2   Sequence
   A          B           1
   A          D           2
   D          B           3
   Z          E           4
   E          D           5

这是代码:

network <- graph.data.frame(data_to_graph[,c(1,2)])

subnetwork <- induced.subgraph(network, vids = 30, impl = 'copy_and_delete', eids = c(5,6,7,8,9,10,11,12,13,14,15))

plot(subnetwork)

我想通过指定第 1 列的元素在距该节点一定距离处绘制图形。

谢谢

达里奥

这是答案:

distan <- 3
node <- "node name"

subnetwork <- induced.subgraph(network, vids = as.vector(unlist(neighborhood(network, distan, nodes = node, mode = 'all'))))

plot.igraph(subnetwork, vertex.size=10)