[英]R Igraph subgraph given node index and number of nodes to include in the graph
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: 我正在绘制的data.frame如下:
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. 我想通过指定第1列的元素来绘制距离该节点一定距离的图形。
Thanks 谢谢
Dario. 达里奥。
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.