简体   繁体   English

如何在igraph中提取子图

[英]How to extract subgraph in igraph

I want to extract a subgraph around that node. 我想在该节点周围提取一个子图。

library(visNetwork)
library(igraph)
library(dplyr)

g<-data.frame(a=c(LETTERS[1:5], LETTERS[2:6]),b=c(LETTERS[2:6],  LETTERS[7:11])) %>% 
        as.matrix %>% graph.edgelist() 

visIgraph(g) %>% 
       visHierarchicalLayout(sortMethod = "directed", 
                             direction = "LR",levelSeparation = 300)

I would like to extract subgraph start from "D", like this 我想从“ D”开始提取子图,像这样

data.frame(a=c(LETTERS[1:5], LETTERS[2:6]), b=c(LETTERS[2:6], LETTERS[7:11])) %>% 
    as.matrix %>% .[c(4,5,8,9,10),1:2] %>% 
    graph.edgelist() %>% visIgraph() %>% 
    visHierarchicalLayout(sortMethod = "directed", 
                          direction = "LR", levelSeparation = 300)

Is there a way to get it? 有办法吗? Thanks. 谢谢。

Have you tried the induced.subgraph() function? 您是否尝试了归纳.subgraph()函数?

new.vertices<- V(g)[-c(1,2,3,7,8)]
g.sub <- induced.subgraph(graph = g, new.vertices)
visIgraph(g.sub) %>% 
  visHierarchicalLayout(sortMethod = "directed", 
                        direction = "LR",levelSeparation = 300)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM