Functions to deal with the result of network community detection
igraph community detection functions return their results
as an object from the
communities class. This manual page
describes the operations of this class.
## S3 method for class 'communities': print(x, \dots)
## S3 method for class 'communities': length(x) sizes(communities) membership(communities) ## S3 method for class 'communities': modularity(x, \dots) algorithm(communities) crossing(communities, graph)
is.hierarchical(communities, full = FALSE) merges(communities) cutat(communities, no, steps) ## S3 method for class 'communities': as.dendrogram(object, hang=-1, use.modularity=FALSE, \dots) ## S3 method for class 'communities': as.hclust(x, hang = -1, use.modularity = FALSE, \dots) ## S3 method for class 'communities': asPhylo(x, use.modularity=FALSE, \dots) showtrace(communities)
## S3 method for class 'communities': plot(x, y, colbar=rainbow(length(x)), col=colbar[membership(x)], mark.groups=communities(x), edge.color=c("black", "red")[crossing(x,y)+1], ...)
communitiesobject, the result of an igraph community detection function.
- An igraph graph object, corresponding to
- Logical scalar, if
TRUEfor fully hierarchical algorithms. The
leading eigenvectoralgorithm is hierarchical, it gives a hierarchy of groups, but not
- An igraph graph object, corresponding to the communities in
- Integer scalar, the desired number of communities. If too
low or two high, then an error message is given. Exactly one of
stepsmust be supplied.
- The number of merge operations to perform to produce the
communities. Exactly one of
stepsmust be supplied.
- A vector of colors, in any format that is accepted by the regular R plotting methods. E.g. it may be an integer vector, a character vector of color names, a character vector of RGB colors. This vector gives the color bar for the vertices. The
- 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.
- 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
NULLhere if you d
- The colors of the edges. By default the edges within communities are colored green and other edges are red.
- Numeric scalar indicating how the height of leaves should
be computed from the heights of their parents; see
- Logical scalar, whether to use the modularity values to define the height of the branches.
- Additional arguments.
plot.communitiespasses these to
plot.igraph. The other functions silently ignore them.
Community structure detection algorithms try to find dense subgraphs in directed or undirected graphs, by optimizing some criteria, and usually using heuristics.
igraph implements a number of commmunity detection methods (see them
below), all of which return an object of the class
communities. Because the community structure detection
algorithms are different,
communities objects do not always
have the same structure. Nevertheless, they have some common
operations, these are documented here.
it prints a short summary.
length generic function call be called on
communities and returns the number of communities.
sizes function returns the community sizes, in the order of
membership 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.
modularity gives the modularity score of the partitioning. (See
modularity.igraph for details. For algorithms that do
not result a single partitioning, the highest modularity value is
algorithm gives the name of the algorithm that was used to
calculate the community structure.
crossing returns a logical vector, with one value for each
edge, ordered according to the edge ids. The value is
the edge connects two different communities, according to the (best)
membership vector, as returned by
is.hierarchical checks whether a hierarchical algorithm was
used to find the community structure. Some functions only make sense
for hierarchical methods (e.g.
merges 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
is.hierarchical on the
cutat 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.
as.dendrogram converts a hierarchical community structure to a
dendrogram object. It only works for hierarchical methods, and
gives an error message to others. See
as.hclust is similar to
as.dendrogram, but converts a
hierarchical community structure to a
asPhylo converts a hierarchical community structure to
phylo object, you will need the
ape package for this.
showtrace works (currently) only for communities found by the
leading eigenvector method
leading.eigenvector.community), and returns a character
vector that gives the steps performed by the algorithm while finding
code.length is defined for the InfoMAP method
infomap.community and returns the code length of the
It is possibly to call the
plot function on
objects. This will plot the graph (and uses
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
plot.igraph, please see that and also
igraph.plotting on how to change the plot.
communitiesobject itself, invisibly.
lengthreturns an integer scalar.
sizesreturns a numeric vector.
membershipreturns a numeric vector, one number for each vertex in the graph that was the input of the community detection.
modularityreturns a numeric scalar.
algorithmreturns a character scalar.
crossingreturns a logical vector.
is.hierarchicalreturns a logical scalar.
mergesreturns a two-column numeric matrix.
cutatreturns a numeric vector, the membership vector of the vertices.
showtracereturns a character vector.
code.lengthreturns a numeric scalar for communities found with the InfoMAP method and
NULLfor other methods.
dendPlot for plotting community structure
compare.communities for comparing two community
structures on the same graph.
The different methods for finding communities, they all return a
karate <- graph.famous("Zachary") wc <- walktrap.community(karate) modularity(wc) membership(wc) plot(wc, karate)