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

帅比萌擦擦* 提交于 2021-01-29 12:10:58

问题


I want to plot a portion of a graph according to a specific node and ideally a distance from that node or a number of nodes as part of the sub graph.

The data.frame that I am graphing is as follows:

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

this is the code:

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)

I would like, by specifying an element of column 1 to plot a graph at a certain distance from that node.

Thanks

Dario.


回答1:


This is the answer:

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)


来源:https://stackoverflow.com/questions/55390780/r-igraph-subgraph-given-node-index-and-number-of-nodes-to-include-in-the-graph

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!