Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

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

share|improve this answer
FYI you can use the notation 1 <-> 2 for undirected edge. – Simon Woods May 21 '14 at 9:32
@SimonWoods: Yeah, should have done that before pasting code... – ciao May 21 '14 at 9:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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