我想在该节点周围提取一个子图。
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)
我想从&#34; D&#34;中提取子图,像这样
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)
有办法搞定吗?感谢。
答案 0 :(得分:0)
您是否尝试过indu.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)