I am doing a coalition analysis on Igraph and I would like to find a way to force the detection of communities to only two. I have tried to achieve this using fastgreedy community detection and walktrap community algorithms with no success. Is this possible to do?
Asked
Active
Viewed 89 times
-1
-
2If this is a question specifically about the code needed to do it, we'd need to see a [reproducible example](https://stackoverflow.com/q/5963269/5325862). If it's about the stats methods behind it (like is it mathematically possible), it should get moved to [stats.se] – camille Sep 09 '21 at 02:13
-
Please provide enough code so others can better understand or reproduce the problem. – Community Sep 09 '21 at 02:49
-
Next time when you say you have tried something, please show what you have done exactly. – Szabolcs Sep 11 '21 at 20:27
1 Answers
1
With community detection methods that return a hierarchical structure (dendrogram), you can use the cut_at
function to get as many communities as you want. This is possible with both walktrap
and fast_greedy
.
cl <- cluster_walktrap(graph)
cut_at(cl, 2)
Please check the documentation at https://igraph.org/r/doc/communities.html

Szabolcs
- 24,728
- 9
- 85
- 174