1
$\begingroup$

I have a graph g. I want a set of graphs c which holds the community subgraphs of g.

I tried c = Subgraph[g, FindGraphCommunities[g]], but it only outputs the whole graph g. I see in the documentation that FindGraphCommunities returns a list of vertices, this may be why. How do I also get the edges?

$\endgroup$

1 Answer 1

3
$\begingroup$

If I understand your query:

g = Graph[{1 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 3, 
   1 \[UndirectedEdge] 3, 3 \[UndirectedEdge] 4, 
   4 \[UndirectedEdge] 5, 7 \[UndirectedEdge] 6, 
   8 \[UndirectedEdge] 6, 5 \[UndirectedEdge] 7, 
   7 \[UndirectedEdge] 8}];

coms = FindGraphCommunities[g];

Row[Subgraph[g, #, VertexLabels -> "Name"] & /@ coms]

enter image description here

$\endgroup$
2
  • 2
    $\begingroup$ FYI you can use the notation 1 <-> 2 for undirected edge. $\endgroup$ May 21, 2014 at 9:32
  • $\begingroup$ @SimonWoods: Yeah, should have done that before pasting code... $\endgroup$
    – ciao
    May 21, 2014 at 9:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.