| communities | R Documentation |
Detects communities in a network with one of the community detection
algorithms of igraph. Each method calls the matching
community_*() function.
communities(
x,
method = c("louvain", "leiden", "fast_greedy", "walktrap", "infomap",
"label_propagation", "edge_betweenness", "leading_eigenvector", "spinglass",
"optimal", "fluid"),
community = NULL,
weights = NULL,
resolution = 1,
directed = NULL,
seed = NULL,
...
)
x |
Network input: matrix, igraph, network, CographNetwork, cograph_network, or tna object. |
method |
Community detection algorithm. One of |
community |
Optional integer or character vector. If supplied, the
returned data frame is filtered to rows whose |
weights |
Edge weights. |
resolution |
Resolution parameter of the louvain and leiden methods. For louvain, higher values yield more communities. Default 1. |
directed |
Logical. Whether the edge betweenness method treats the
network as directed. |
seed |
Random seed for reproducibility. It applies to the stochastic methods (louvain, leiden, infomap, label_propagation, spinglass). |
... |
Additional arguments passed to the |
The louvain, leiden, fast_greedy, leading_eigenvector and fluid methods
require an undirected graph. For a directed input this function prints a
message and runs "walktrap" instead. Called directly,
community_louvain() and community_leiden() raise an igraph
error on a directed graph, while community_fast_greedy(),
community_leading_eigenvector() and community_fluid()
collapse it to an undirected graph with summed weights.
Negative edge weights are replaced by their absolute values for all methods except spinglass and optimal, which receive the weights as they are.
| Method | Typical use |
| louvain | Large undirected networks |
| leiden | Large undirected networks, well-connected communities |
| fast_greedy | Medium-sized networks, hierarchical merges |
| walktrap | Directed or undirected networks, hierarchical merges |
| infomap | Directed networks with flow structure |
| label_propagation | Very large networks |
| edge_betweenness | Small networks, hierarchical splits |
| leading_eigenvector | Undirected networks, hierarchical splits |
| spinglass | Small connected networks, negative weights |
| optimal | Networks of at most about 50 nodes |
| fluid | Connected networks with a known number of communities |
A cograph_communities data frame with one row per node and
the columns
Node label (character).
Community number (numeric).
The attributes "algorithm" (method name), "modularity"
(modularity of the partition, NA when igraph does not compute
it), "network" (the input x) and "igraph_result"
(the igraph communities object) hold the metadata. When
community is supplied, only the matching rows are kept.
Printing the result shows the algorithm, the number of nodes and
communities, the modularity, the community sizes and the node table. The
result is itself a data frame.
plot() on the result is documented in plot-results.
community_louvain, community_leiden,
community_fast_greedy, community_walktrap,
community_infomap, community_label_propagation,
community_edge_betweenness, community_leading_eigenvector,
community_spinglass, community_optimal,
community_fluid
communities(regulation_net, method = "walktrap")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.