按节点拆分图

Splitting a graph by a node

我有一个图表,我想用一个节点分割它。这是下面介绍的。

我正在使用 R tidygraph。它具有 to_splitto_components 的变形功能,但我找不到合适的文档来实现它。任何线索都会有所帮助。

igraph

的可能选项
library(igraph)
g <- graph_from_data_frame(df, directed = FALSE)
v <- "3"
v.neighbor <- neighbors(g, v)
v.new <- paste0(v, "_", seq_along(v.neighbor))
gout <- g %>%
    delete.vertices(v) %>%
    add.vertices(nv = length(v.neighbor), name = v.new) %>%
    add.edges(c(rbind(v.new, names(v.neighbor))))

plot(gout)显示

数据

df <- data.frame(
    from = c(1, 2, 3, 3, 4, 7, 5),
    to = c(2, 3, 4, 5, 7, 8, 10)
)