Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

1 Answer 1

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
2  
FYI you can use the notation 1 <-> 2 for undirected edge. –  Simon Woods May 21 at 9:32
    
@SimonWoods: Yeah, should have done that before pasting code... –  rasher May 21 at 9:34

Your Answer

 
discard

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.