在 R 中查找所有封闭节点集

Find all sets of closed nodes in R

我有一个边列表如下(简单示例):

DT <- data.frame(x = c(letters[1:7],"a","b","c","a","d","e","f"), y = c(letters[1:7],"b","a","a","c","f","f","d"))
> DT
   x y
1  a a
2  b b
3  c c
4  d d
5  e e
6  f f
7  g g
8  a b
9  b a
10 c a
11 a c
12 d f
13 e f
14 f d

然后我使用以下代码绘制了图表:

require(igraph)
myadj <- get.adjacency(graph.edgelist(as.matrix(DT), directed=FALSE))
my_graph <- graph.adjacency(myadj)
layout <- layout.fruchterman.reingold(my_graph,niter=500,area=vcount(my_graph)^2.3,repulserad=vcount(my_graph)^2.8)
plot(my_graph, vertex.size=10, 
     vertex.label.cex=1,
     edge.arrow.size=0, edge.curved=TRUE,layout=layout)

我现在要做的是提取所有闭合节点的集合。我不确定典型的符号是什么样的,但我可以想象:

  node set
1    a   1
2    b   1
3    c   1
4    d   2
5    e   2
6    f   2
7    g   3

我四处寻找 functions/algorithms,但我认为我无法正确表达我在寻找什么。由于我对图论很陌生,所以我也不确定开始使用的正确格式。使用边列表、邻接矩阵(稀疏或完整)或其他方式最简单吗?

尝试

data.frame(node = V(my_graph)$name, set = membership(clusters(my_graph)))
#   node set
# 1    a   1
# 2    b   1
# 3    c   1
# 4    d   2
# 5    e   2
# 6    f   2
# 7    g   3