我有一个边缘列表如下(简单示例):
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
我一直在寻找功能/算法,但我不认为我能够清楚地表达我正在寻找的东西。由于我是图论的新手,我也不确定正确的格式。这是最简单的边缘列表,邻接矩阵(稀疏或完整)还是其他?
答案 0 :(得分:5)
尝试
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