graph theory - Find all sets of closed nodes in R -
i have edge list follows (simple example):
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 2 b b 3 c c 4 d d 5 e e 6 f f 7 g g 8 b 9 b 10 c 11 c 12 d f 13 e f 14 f d
i graphed using following code:
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)
what go extract set of closed nodes. i'm not sure typical notation like, imagine:
node set 1 1 2 b 1 3 c 1 4 d 2 5 e 2 6 f 2 7 g 3
i have looked around functions/algorithms, don't think have been able articulate looking properly. new graph theory, not sure of right format start with. easiest edge list, adjacency matrix (sparse or full) or otherwise?
try
data.frame(node = v(my_graph)$name, set = membership(clusters(my_graph))) # node set # 1 1 # 2 b 1 # 3 c 1 # 4 d 2 # 5 e 2 # 6 f 2 # 7 g 3
Comments
Post a Comment