EVOLUTION-MANAGER
Edit File: communities.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Functions to deal with the result of network community...</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for membership {igraph}"><tr><td>membership {igraph}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Functions to deal with the result of network community detection</h2> <h3>Description</h3> <p>igraph community detection functions return their results as an object from the <code>communities</code> class. This manual page describes the operations of this class. </p> <h3>Usage</h3> <pre> membership(communities) ## S3 method for class 'communities' print(x, ...) ## S3 method for class 'communities' modularity(x, ...) ## S3 method for class 'communities' length(x) sizes(communities) algorithm(communities) merges(communities) crossing(communities, graph) code_len(communities) is_hierarchical(communities) ## S3 method for class 'communities' as.dendrogram(object, hang = -1, use.modularity = FALSE, ...) ## S3 method for class 'communities' as.hclust(x, hang = -1, use.modularity = FALSE, ...) as_phylo(x, ...) ## S3 method for class 'communities' as_phylo(x, use.modularity = FALSE, ...) cut_at(communities, no, steps) show_trace(communities) ## S3 method for class 'communities' plot( x, y, col = membership(x), mark.groups = communities(x), edge.color = c("black", "red")[crossing(x, y) + 1], ... ) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>communities, x, object</code></td> <td> <p>A <code>communities</code> object, the result of an igraph community detection function.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>Additional arguments. <code>plot.communities</code> passes these to <code><a href="plot.igraph.html">plot.igraph</a></code>. The other functions silently ignore them.</p> </td></tr> <tr valign="top"><td><code>graph</code></td> <td> <p>An igraph graph object, corresponding to <code>communities</code>.</p> </td></tr> <tr valign="top"><td><code>hang</code></td> <td> <p>Numeric scalar indicating how the height of leaves should be computed from the heights of their parents; see <code><a href="../../stats/html/hclust.html">plot.hclust</a></code>.</p> </td></tr> <tr valign="top"><td><code>use.modularity</code></td> <td> <p>Logical scalar, whether to use the modularity values to define the height of the branches.</p> </td></tr> <tr valign="top"><td><code>no</code></td> <td> <p>Integer scalar, the desired number of communities. If too low or two high, then an error message is given. Exactly one of <code>no</code> and <code>steps</code> must be supplied.</p> </td></tr> <tr valign="top"><td><code>steps</code></td> <td> <p>The number of merge operations to perform to produce the communities. Exactly one of <code>no</code> and <code>steps</code> must be supplied.</p> </td></tr> <tr valign="top"><td><code>y</code></td> <td> <p>An igraph graph object, corresponding to the communities in <code>x</code>.</p> </td></tr> <tr valign="top"><td><code>col</code></td> <td> <p>A vector of colors, in any format that is accepted by the regular R plotting methods. This vector gives the colors of the vertices explicitly.</p> </td></tr> <tr valign="top"><td><code>mark.groups</code></td> <td> <p>A list of numeric vectors. The communities can be highlighted using colored polygons. The groups for which the polygons are drawn are given here. The default is to use the groups given by the communities. Supply <code>NULL</code> here if you do not want to highlight any groups.</p> </td></tr> <tr valign="top"><td><code>edge.color</code></td> <td> <p>The colors of the edges. By default the edges within communities are colored green and other edges are red.</p> </td></tr> <tr valign="top"><td><code>membership</code></td> <td> <p>Numeric vector, one value for each vertex, the membership vector of the community structure. Might also be <code>NULL</code> if the community structure is given in another way, e.g. by a merge matrix.</p> </td></tr> <tr valign="top"><td><code>algorithm</code></td> <td> <p>If not <code>NULL</code> (meaning an unknown algorithm), then a character scalar, the name of the algorithm that produced the community structure.</p> </td></tr> <tr valign="top"><td><code>merges</code></td> <td> <p>If not <code>NULL</code>, then the merge matrix of the hierarchical community structure. See <code>merges</code> below for more information on its format.</p> </td></tr> <tr valign="top"><td><code>modularity</code></td> <td> <p>Numeric scalar or vector, the modularity value of the community structure. It can also be <code>NULL</code>, if the modularity of the (best) split is not available.</p> </td></tr> </table> <h3>Details</h3> <p>Community structure detection algorithms try to find dense subgraphs in directed or undirected graphs, by optimizing some criteria, and usually using heuristics. </p> <p>igraph implements a number of community detection methods (see them below), all of which return an object of the class <code>communities</code>. Because the community structure detection algorithms are different, <code>communities</code> objects do not always have the same structure. Nevertheless, they have some common operations, these are documented here. </p> <p>The <code>print</code> generic function is defined for <code>communities</code>, it prints a short summary. </p> <p>The <code>length</code> generic function call be called on <code>communities</code> and returns the number of communities. </p> <p>The <code>sizes</code> function returns the community sizes, in the order of their ids. </p> <p><code>membership</code> gives the division of the vertices, into communities. It returns a numeric vector, one value for each vertex, the id of its community. Community ids start from one. Note that some algorithms calculate the complete (or incomplete) hierarchical structure of the communities, and not just a single partitioning. For these algorithms typically the membership for the highest modularity value is returned, but see also the manual pages of the individual algorithms. </p> <p><code>communities</code> is also the name of a function, that returns a list of communities, each identified by their vertices. The vertices will have symbolic names if the <code>add.vertex.names</code> igraph option is set, and the graph itself was named. Otherwise numeric vertex ids are used. </p> <p><code>modularity</code> gives the modularity score of the partitioning. (See <code><a href="modularity.igraph.html">modularity.igraph</a></code> for details. For algorithms that do not result a single partitioning, the highest modularity value is returned. </p> <p><code>algorithm</code> gives the name of the algorithm that was used to calculate the community structure. </p> <p><code>crossing</code> returns a logical vector, with one value for each edge, ordered according to the edge ids. The value is <code>TRUE</code> iff the edge connects two different communities, according to the (best) membership vector, as returned by <code>membership()</code>. </p> <p><code>is_hierarchical</code> checks whether a hierarchical algorithm was used to find the community structure. Some functions only make sense for hierarchical methods (e.g. <code>merges</code>, <code>cut_at</code> and <code>as.dendrogram</code>). </p> <p><code>merges</code> returns the merge matrix for hierarchical methods. An error message is given, if a non-hierarchical method was used to find the community structure. You can check this by calling <code>is_hierarchical</code> on the <code>communities</code> object. </p> <p><code>cut_at</code> cuts the merge tree of a hierarchical community finding method, at the desired place and returns a membership vector. The desired place can be expressed as the desired number of communities or as the number of merge steps to make. The function gives an error message, if called with a non-hierarchical method. </p> <p><code>as.dendrogram</code> converts a hierarchical community structure to a <code>dendrogram</code> object. It only works for hierarchical methods, and gives an error message to others. See <code><a href="../../stats/html/dendrogram.html">dendrogram</a></code> for details. </p> <p><code>as.hclust</code> is similar to <code>as.dendrogram</code>, but converts a hierarchical community structure to a <code>hclust</code> object. </p> <p><code>as_phylo</code> converts a hierarchical community structure to a <code>phylo</code> object, you will need the <code>ape</code> package for this. </p> <p><code>show_trace</code> works (currently) only for communities found by the leading eigenvector method (<code><a href="cluster_leading_eigen.html">cluster_leading_eigen</a></code>), and returns a character vector that gives the steps performed by the algorithm while finding the communities. </p> <p><code>code_len</code> is defined for the InfoMAP method (<code><a href="cluster_infomap.html">cluster_infomap</a></code> and returns the code length of the partition. </p> <p>It is possibly to call the <code>plot</code> function on <code>communities</code> objects. This will plot the graph (and uses <code><a href="plot.igraph.html">plot.igraph</a></code> internally), with the communities shown. By default it colores the vertices according to their communities, and also marks the vertex groups corresponding to the communities. It passes additional arguments to <code><a href="plot.igraph.html">plot.igraph</a></code>, please see that and also <code><a href="plot.common.html">igraph.plotting</a></code> on how to change the plot. </p> <h3>Value</h3> <p><code>print</code> returns the <code>communities</code> object itself, invisibly. </p> <p><code>length</code> returns an integer scalar. </p> <p><code>sizes</code> returns a numeric vector. </p> <p><code>membership</code> returns a numeric vector, one number for each vertex in the graph that was the input of the community detection. </p> <p><code>modularity</code> returns a numeric scalar. </p> <p><code>algorithm</code> returns a character scalar. </p> <p><code>crossing</code> returns a logical vector. </p> <p><code>is_hierarchical</code> returns a logical scalar. </p> <p><code>merges</code> returns a two-column numeric matrix. </p> <p><code>cut_at</code> returns a numeric vector, the membership vector of the vertices. </p> <p><code>as.dendrogram</code> returns a <code><a href="../../stats/html/dendrogram.html">dendrogram</a></code> object. </p> <p><code>show_trace</code> returns a character vector. </p> <p><code>code_len</code> returns a numeric scalar for communities found with the InfoMAP method and <code>NULL</code> for other methods. </p> <p><code>plot</code> for <code>communities</code> objects returns <code>NULL</code>, invisibly. </p> <p>#' @author Gabor Csardi <a href="mailto:csardi.gabor@gmail.com">csardi.gabor@gmail.com</a> </p> <h3>See Also</h3> <p>See <code><a href="plot_dendrogram.communities.html">plot_dendrogram</a></code> for plotting community structure dendrograms. </p> <p>See <code><a href="compare.html">compare</a></code> for comparing two community structures on the same graph. </p> <p>The different methods for finding communities, they all return a <code>communities</code> object: <code><a href="cluster_edge_betweenness.html">cluster_edge_betweenness</a></code>, <code><a href="cluster_fast_greedy.html">cluster_fast_greedy</a></code>, <code><a href="cluster_label_prop.html">cluster_label_prop</a></code>, <code><a href="cluster_leading_eigen.html">cluster_leading_eigen</a></code>, <code><a href="cluster_louvain.html">cluster_louvain</a></code>, <code><a href="cluster_leiden.html">cluster_leiden</a></code>, <code><a href="cluster_optimal.html">cluster_optimal</a></code>, <code><a href="cluster_spinglass.html">cluster_spinglass</a></code>, <code><a href="cluster_walktrap.html">cluster_walktrap</a></code>. </p> <h3>Examples</h3> <pre> karate <- make_graph("Zachary") wc <- cluster_walktrap(karate) modularity(wc) membership(wc) plot(wc, karate) </pre> <hr /><div style="text-align: center;">[Package <em>igraph</em> version 1.3.5 <a href="00Index.html">Index</a>]</div> </body></html>