Title: | Tools for Generating, Visualizing, and Analysing Link Communities in Networks |
---|---|
Description: | Link communities reveal the nested and overlapping structure in networks, and uncover the key nodes that form connections to multiple communities. linkcomm provides a set of tools for generating, visualizing, and analysing link communities in networks of arbitrary size and type. The linkcomm package also includes tools for generating, visualizing, and analysing Overlapping Cluster Generator (OCG) communities. Kalinka and Tomancak (2011) <doi:10.1093/bioinformatics/btr311>. |
Authors: | Alex T. Kalinka <[email protected]>, with contributions from Alain Guenoche |
Maintainer: | Alex T. Kalinka <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0-14 |
Built: | 2025-02-22 03:39:27 UTC |
Source: | https://github.com/alextkalinka/linkcomm |
linkcomm
packagelinkcomm
provides tools for the generation, visualization, and analysis of link communities in networks of arbitrary size and type.
Link communities reveal the nested and overlapping structure in networks, and uncover the key nodes that form connections to multiple communities. linkcomm
provides tools for generating, visualizing, and analysing link communities in networks of arbitrary size and type.
For a more detailed overview of how to use the package:vignette(topic = "linkcomm", package = "linkcomm")
To run an interactive demonstration of linkcomm
within R:demo(topic = "linkcomm", package = "linkcomm")
Alex T. Kalinka [email protected]
Ahn, Y.Y., Bagrow, J.P., and Lehmann, S. (2010). Link communities reveal multiscale complexity in networks. Nature 466, 761-764.
Becker, E., Robisson, B., Chapple, C.E., Guenoche, A. and Brun, C. (2012) Multifunctional proteins revealed by overlapping clustering in protein interaction network. Bioinformatics 28, 84-90.
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
Spencer, R. (2010). http://scaledinnovation.com/analytics/communities/comlinks.html
getLinkCommunities
, getOCG.clusters
, plot.linkcomm
, pp_rnapol
, lesmiserables
, karate
, weighted
, igraph
, RColorBrewer
, grid
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Plot a graph layout of the link communities. plot(lc, type = "graph") ## Use a Spencer circle layout. plot(lc, type = "graph", layout = "spencer.circle") ## Calculate a community-based measure of node centrality. getCommunityCentrality(lc) ## Find nested communities. getAllNestedComm(lc) ## Uncover the relatedness between communities. getClusterRelatedness(lc)
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Plot a graph layout of the link communities. plot(lc, type = "graph") ## Use a Spencer circle layout. plot(lc, type = "graph", layout = "spencer.circle") ## Calculate a community-based measure of node centrality. getCommunityCentrality(lc) ## Find nested communities. getAllNestedComm(lc) ## Uncover the relatedness between communities. getClusterRelatedness(lc)
This function calculates the correlation between the community centrality and classic centrality measures for a set of nodes in a network, and plots a scatterplot of the relationship together with a fitted straight line.
corLinkcommCentrality(x, centrality = "degree", type = "commweight", method = "spearman", plot = TRUE, pch = 20, ...)
corLinkcommCentrality(x, centrality = "degree", type = "commweight", method = "spearman", plot = TRUE, pch = 20, ...)
x |
An object of class |
centrality |
A character string naming the classic centrality measure. Can be one of |
type |
A character string naming the type of community centrality. Can be |
method |
A character string naming the correlation method. Can be one of |
plot |
Logical, whether to plot a scatterplot of the relationship, defaults to TRUE. |
pch |
An integer specifying the plot symbol (see |
... |
Additional arguments to be passed to |
The correlation between community centrality and classic centrality measures, such as degree or betweenness, may reveal discrepancies, thereby indicating that community centrality scores provide a unique reflection of node importance.
A correlation coefficient.
Alex T. Kalinka [email protected]
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Correlate community centrality with degree centrality. corLinkcommCentrality(lc)
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Correlate community centrality with degree centrality. corLinkcommCentrality(lc)
This function extracts meta-communities from a dendrogram of community relatedness based on a user-defined place at which to cut the dendrogram.
cutDendrogramAt(x, lc = NULL, cutat = NULL, plot = TRUE, col = TRUE, pal = brewer.pal(9, "Set1"), labels = FALSE, plotcut = TRUE, right = TRUE, verbose = TRUE, ...)
cutDendrogramAt(x, lc = NULL, cutat = NULL, plot = TRUE, col = TRUE, pal = brewer.pal(9, "Set1"), labels = FALSE, plotcut = TRUE, right = TRUE, verbose = TRUE, ...)
x |
An object of class |
lc |
An object of class |
cutat |
A numerical value at which to cut the dendrogram. |
plot |
Logical, whether to plot the dendrogram and the meta-communities, defaults to TRUE. |
col |
Logical, whether to colour the meta-communites. |
pal |
A character vector describing a colour palette to be used for colouring the meta-communites in the dendrogram plot. Defaults to |
labels |
Logical, whether to put labels on the dendrogram. Defaults to FALSE. |
plotcut |
Logical, whether to display a horizontal line where the dendrogram is cut. Defaults to TRUE. |
right |
Logical, whether to orient the dendrogram to the right. Defaults to TRUE. |
verbose |
Logical, whether to display the progress of colouring the dendrogram. Defaults to TRUE. |
... |
Additional arguments to be passed to |
Extracting meta-communities allows the user to explore community relatedness and structure at higher levels.
A list of integer vectors, referring to meta-communities of link communities.
Alex T. Kalinka [email protected]
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
## Generate graph, extract link communities, and cluster communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) hc <- getClusterRelatedness(lc) ## Cut dendrogram at 1 and extract meta-communities. cutDendrogramAt(hc, cutat = 1)
## Generate graph, extract link communities, and cluster communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) hc <- getClusterRelatedness(lc) ## Cut dendrogram at 1 and extract meta-communities. cutDendrogramAt(hc, cutat = 1)
This function finds and removes loops, edge duplicates, and bi-directional edges.
edge.duplicates(network, verbose = TRUE)
edge.duplicates(network, verbose = TRUE)
network |
An edge list, which is either a data frame or a character or integer matrix with two columns. |
verbose |
Logical, whether to display the progress of the function on the screen. Defaults to TRUE. |
This function removes loops, duplicate and bi-directional edges; the edges that occur closer to the end of the edge list will be removed.
A list with the following elements: edges
- a character matrix of the edges in the network with any loops or duplicate edges removed; inds
- an integer vector of the edge indices of any loop or duplicate edges in the original network.
Alex T. Kalinka [email protected]
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
## Generate graph and remove loops and duplicate edges. g <- swiss[,3:4] g.dup <- edge.duplicates(g)
## Generate graph and remove loops and duplicate edges. g <- swiss[,3:4] g.dup <- edge.duplicates(g)
This function returns lists of communities that share at least one node with each other.
get.community.overlaps(x)
get.community.overlaps(x)
x |
An object of class |
A list of length equal to the number of communities. Each element contains an integer vector giving the community IDs for communities sharing at least one node with each community. NAs indicate that a community shares no nodes with any other communities.
Alex T. Kalinka [email protected]
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Get list of overlapping communities. ov <- get.community.overlaps(lc)
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Get list of overlapping communities. ov <- get.community.overlaps(lc)
This function returns communities of nodes that are entirely nested within other larger communities of nodes.
getAllNestedComm(x, verbose = FALSE, plot = FALSE)
getAllNestedComm(x, verbose = FALSE, plot = FALSE)
x |
An object of class |
verbose |
Logical, whether to print to the screen a warning that individual community IDs are not clustered in any other communities. Defaults to FALSE. |
plot |
Logical, whether to plot graphs of the nested communities. Defaults to FALSE. |
Nested community structures may reveal interesting relationships among sets of nodes.
A named list of integer vectors; names are integers referring to nested communities, and the integer vectors are the communities that the named community is nested in.
Alex T. Kalinka [email protected]
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Find nested communities. getAllNestedComm(lc)
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Find nested communities. getAllNestedComm(lc)
This function hierarchically clusters the link communities themselves and returns an object of class hclust
.
getClusterRelatedness(x, clusterids = 1:x$numbers[3], hcmethod = "ward.D", cluster = TRUE, plot = TRUE, cutat = NULL, col = TRUE, pal = brewer.pal(11, "Spectral"), labels = FALSE, plotcut = TRUE, right = TRUE, verbose = TRUE, ...)
getClusterRelatedness(x, clusterids = 1:x$numbers[3], hcmethod = "ward.D", cluster = TRUE, plot = TRUE, cutat = NULL, col = TRUE, pal = brewer.pal(11, "Spectral"), labels = FALSE, plotcut = TRUE, right = TRUE, verbose = TRUE, ...)
x |
An object of class |
clusterids |
An integer vector of community IDs. Defaults to all communities. |
hcmethod |
A character string naming the hierarchical clustering method to use. Can be one of |
cluster |
Logical, whether to cluster the communities. If FALSE, the function returns the upper triangular dissimilarity matrix as a vector. Defaults to TRUE. |
plot |
Logical, whether to plot the cluster dendrogram. |
cutat |
A numerical value at which to cut the dendrogram. If NULL, the dendrogram is not cut and meta-communities are not returned. Defaults to NULL. |
col |
Logical, whether to colour the dendrogram. Defaults to TRUE. |
pal |
A character vector describing a colour palette to be used for colouring the meta-communites in the dendrogram plot. Defaults to |
labels |
Logical, whether to add labels to the dendrogram plot. |
plotcut |
Logical, whether to display a horizontal line where the dendrogram is cut. Defaults to TRUE. |
right |
Logical, whether to orient the dendrogram to the right. Defaults to TRUE. |
verbose |
Logical, whether to display the progress of the calculation on the screen. Defaults to TRUE. |
... |
Additional arguments to be passed to |
Extracting meta-communities allows the user to explore community relatedness and structure at higher levels. Community relatedness is calculated using the Jaccard coefficient and the number of nodes that community i and j share:
Either a numerical vector (the upper triangular dissimilarity matrix - if cluster = FALSE
), a list of integer vectors (the meta-communities - if cutat
is not NULL), or an object of class hclust
(if cluster
is TRUE and cutat
is NULL).
Alex T. Kalinka [email protected]
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
meta.communities
, cutDendrogramAt
, hclust
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Cluster the link communities. getClusterRelatedness(lc) ## Cluster the link communities, cut the dendrogram, and return the meta-communities. getClusterRelatedness(lc, cutat = 1)
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Cluster the link communities. getClusterRelatedness(lc) ## Cluster the link communities, cut the dendrogram, and return the meta-communities. getClusterRelatedness(lc, cutat = 1)
This function returns community-based node centrality measures.
getCommunityCentrality(x, nodes = names(x$numclusters), type = "commweight", normalise = TRUE)
getCommunityCentrality(x, nodes = names(x$numclusters), type = "commweight", normalise = TRUE)
x |
An object of class |
nodes |
A character vector giving the names of nodes for calculating community centrality scores. Defaults to all nodes. |
type |
A character string naming the community centrality measure. Can be one of |
normalise |
Logical, whether to normalise community connectedness for |
Community-based measures of node centrality provide an alternative to classic measures of node centrality. "commweight"
weights each community that a node belongs to by how similar that community is to each of the other communities to which the node also belongs. For node i the community centrality is
where the main sum is over the communities to which node
belongs, and
refers to the similarity between community
and
, calculated as the Jaccard coefficient for the number of shared nodes between each community pair, and this is averaged over the
communities paired with community
and in which node
jointly belongs.
"commconn"
weights each community that a node belongs to by how many connections the community forms outside of itself relative to how many connections the community has within itself (the inverse of modularity), so that nodes that belong to more highly connecting communitites will receive a higher community centrality score. For node i the community centrality is
where is the number of edges node i has in community j,
is the number of edges community j makes outside of itself normalised by the number of nodes in community j multiplied by the average degree in the network, and
is the number of edges within community j normalised by the total number possible.
A named numerical vector where the names are node names and the numbers are community centrality measures.
Alex T. Kalinka [email protected]
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Calculate community centrality. cc <- getCommunityCentrality(lc)
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Calculate community centrality. cc <- getCommunityCentrality(lc)
This function returns a measure of how relatively outwardly or inwardly connected a community is.
getCommunityConnectedness(x, clusterids = 1:x$numbers[3], conn = "conn", normalise = TRUE, verbose = FALSE)
getCommunityConnectedness(x, clusterids = 1:x$numbers[3], conn = "conn", normalise = TRUE, verbose = FALSE)
x |
An object of class |
clusterids |
An integer vector of community IDs. Defaults to all communities. |
conn |
A character string naming the connectedness measure to use. Can be one of |
normalise |
Logical, whether to normalise community connectedness measures by the number of nodes in individual communities. Defaults to TRUE. |
verbose |
Logical, whether to display the progress of the calculation on the screen. Defaults to FALSE. |
The connectedness and modularity of different communities indicates whether a particular community is bridging several other communities, or existing as a relatively isolated module. The modularity of community i is
where is the number of edges within community i,
is the number of edges community i makes to other communities,
is the number of nodes in community i, and
is the average degree in the network. Community connectedness is the inverse of this value.
A named numerical vector, where the names are community IDs and the numbers are community connectedness or modularity scores.
Alex T. Kalinka [email protected]
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Get community connectedness. cc <- getCommunityConnectedness(lc, normalise = FALSE)
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Get community connectedness. cc <- getCommunityConnectedness(lc, normalise = FALSE)
This function returns a binary matrix with nodes as rows, communities as columns, and unit entries indicating membership in a community.
getCommunityMatrix(x, nodes = head(names(x$numclusters), 20))
getCommunityMatrix(x, nodes = head(names(x$numclusters), 20))
x |
An object of class |
nodes |
A character vector containing the nodes for the community membership matrix. Defaults to the 20 (or less) nodes that belong to the most communities. |
A binary matrix with nodes as rows and communities as columns.
Alex T. Kalinka [email protected]
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Get community membership matrix. getCommunityMatrix(lc)
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Get community membership matrix. getCommunityMatrix(lc)
This function returns edge indices that belong to certain communities or that are incident upon certain nodes.
getEdgesIn(x, clusterids = 1, nodes = NULL, all = FALSE)
getEdgesIn(x, clusterids = 1, nodes = NULL, all = FALSE)
x |
An object of class |
clusterids |
An integer vector of community IDs. Defaults to community 1. |
nodes |
A character vector specifying node(s) for which edge indices should be returned. Overrides |
all |
Logical, whether the edges for all communities to which the named nodes belong should be returned. Will have an effect only if |
An integer vector of edge indices.
Alex T. Kalinka [email protected]
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Get edges from community 1. getEdgesIn(lc)
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Get edges from community 1. getEdgesIn(lc)
This function extracts link communities from networks of arbitrary size and type.
getLinkCommunities(network, hcmethod = "average", use.all.edges = FALSE, edglim = 10^4, directed = FALSE, dirweight = 0.5, bipartite = FALSE, dist = NULL, plot = TRUE, check.duplicates = TRUE, removetrivial = TRUE, verbose = TRUE)
getLinkCommunities(network, hcmethod = "average", use.all.edges = FALSE, edglim = 10^4, directed = FALSE, dirweight = 0.5, bipartite = FALSE, dist = NULL, plot = TRUE, check.duplicates = TRUE, removetrivial = TRUE, verbose = TRUE)
network |
An edge list, which is a matrix or data frame with 2 or 3 columns. The first 2 columns contain the nodes that interact with each other, which can be character strings or integer values. The optional third column is a numerical vector of weights for each edge. Can also be a character string naming a file containing an edge list. |
hcmethod |
A character string naming the hierarchical clustering method to use. Can be one of |
use.all.edges |
Logical, indicating whether edge similarities should be calculated for all pairs of edges (TRUE), or only for edge pairs that share a node (FALSE) as in the original Ahn et al. (2010) algorithm. Defaults to FALSE. If TRUE, networks are treated as undirected. |
edglim |
An integer value indicating the largest number of edges permissible for the hierarchical clustering to be handled in memory. Above this value the upper triangular dissimilarity matrix will be written to disk and read and written as clustering proceeds until the file size is 0 bytes (see Details below). Defaults to |
directed |
Logical, whether the network is directed. Defaults to FALSE. |
dirweight |
A numerical value between 1 and 0 inclusive indicating the weight that will be attached to edges that share a node but are in the opposite orientation. Defaults to 0.5. Will be ignored if |
bipartite |
Logical, whether the input network is bi-partite. See Details for an explanation of how bi-partite networks are handled. Defaults to FALSE. |
dist |
An object of class |
plot |
Logical, whether to plot summary output from the algorithm (dendrogram and partition density plot). Defaults to TRUE. Note, if there are more than 1500 but less than edglim edges then the dendrogram will be plotted without colour and in a separate panel from the partition density to avoid lengthy rendering times; when there are more than edglim edges then only the partition density will be plotted. |
check.duplicates |
Logical, whether to check for and remove loops, duplicate edges, and bi-directional edges. Defaults to TRUE. Note, if you wish to avoid this step by setting this parameter to FALSE then you must be certain that there are no duplicate edges in the network. |
removetrivial |
Logical, whether to remove trivial community clusters that contain 2 edges. Defaults to TRUE. |
verbose |
Logical, whether to display the progress of the algorithm on the screen. Defaults to TRUE. |
This is the main algorithm used for extracting link communities from networks of arbitrary size and type. Input networks may be directed, weighted, both directed and weighted, or neither. The algorithm used is the one outlined by Ahn et al. (2010). The similarity between links, and
, that share a node,
, is calculated using the Jaccard coefficient
where refers to the first-order node neighbourhood of node
, which includes node
itself (inclusive neighbour set). After assigning pairwise similarities to all of the links in the network, the links are hierarchically clustered using single-linkage clustering, and the resulting dendrogram is cut at a point that maximises the density of links within the clusters normalising against the maximum and minimum numbers of links possible in each cluster, known as the partition density.
For directed and weighted networks, the Tanimoto coefficient is used for assigning similarity between links
where refers to a vector describing the weights of links between node
and the nodes in the first-order neighbourhoods of both nodes
and
(equal to 0 in the event of an absent link). For directed networks, links to nodes shared by both node
and
are given a user-defined weight below 1 if they are in the opposite orientation.
For bi-partite networks, the set of neighbours (instead of the inclusive neighbour set) is used to count nodes for the edge similarity metric because node and node
cannot share an edge in a bi-partite network. The partition density for bi-partite networks is calculated as:
where is the total number of edges,
is the number of edges in subset
,
is the number of nodes in subset
,
is the number of nodes in partition 0, and
is the number of nodes in partition 1.
An object of class linkcomm
, which is a list containing the following components:
numbers |
An integer vector with the number of edges, nodes, and communities. |
hclust |
An object of class |
pdmax |
A numerical value indicating the height of the dendrogram at which the partition density is maximised. |
pdens |
A numerical matrix with 2 columns; the first is the heights at which clusters appear and the second is the partition density. |
nodeclusters |
A data frame consisting of 2 columns; the first contains node names, and the second contains single community IDs for each node. All communities and their nodes are represented, but not necessarily all nodes. |
clusters |
A list of integer vectors containing the link IDs that belong to each community. Community IDs are the numerical position of the communities in the list. |
edges |
A data frame with 3 columns; the first two contain nodes that interact with each other, and the third is an integer vector of community IDs indicating community membership for each link. |
numclusters |
A named integer vector. Names are node names and integer values are the number of communities to which each node belongs. |
clustsizes |
A named integer vector. Names are community IDs and integer values indicate the number of nodes that belong in each community. |
igraph |
An object of class |
edgelist |
A character matrix with 2 columns containing the nodes that interact with each other. |
directed |
Logical indicating whether the network is directed. |
bipartite |
Logical indicating whether the network is bi-partite. |
When the number of links is less than edglim
the hierarchical clustering will be handled in memory. Above this value the upper triangular dissimilarity matrix will be compressed and written to disk and read and written as clustering proceeds until the file size is 0 bytes using a compiled C++ function. In this case the hierarchical clustering method will always be "single"
to enhance performance for large networks. The size of edglim
can be modified to suit the computer resources available to the user. As a guide, a network with links will require
MB to be handled in an uncompressed format in the memory.
For directed networks, a pair of bidirectional interactions between two nodes cannot be assigned similarities and the edge that appears lower in the edge list for the network will be discarded.
When use.all.edges
is TRUE, the algorithm may be slow as all pairs of edges will be compared ( comparisons, where
is the number of edges).
Alex T. Kalinka [email protected]
Ahn, Y.Y., Bagrow, J.P., and Lehmann, S. (2010). Link communities reveal multiscale complexity in networks. Nature 466, 761-764.
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
plot.linkcomm
, newLinkCommsAt
, meta.communities
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Extract communities by writing a temporary file to disk. lc <- getLinkCommunities(g, edglim = 10) ## Use similarities between all pairs of edges. lc <- getLinkCommunities(g, use.all.edges = TRUE) ## Directed network. lc <- getLinkCommunities(g, directed = TRUE, dirweight = 0.8) ## Weighted network. g <- cbind(swiss[,3:4], runif(nrow(swiss[,3:4]))) lc <- getLinkCommunities(g) ## Directed and weighted network. lc <- getLinkCommunities(g, directed = TRUE, dirweight = 0.8)
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Extract communities by writing a temporary file to disk. lc <- getLinkCommunities(g, edglim = 10) ## Use similarities between all pairs of edges. lc <- getLinkCommunities(g, use.all.edges = TRUE) ## Directed network. lc <- getLinkCommunities(g, directed = TRUE, dirweight = 0.8) ## Weighted network. g <- cbind(swiss[,3:4], runif(nrow(swiss[,3:4]))) lc <- getLinkCommunities(g) ## Directed and weighted network. lc <- getLinkCommunities(g, directed = TRUE, dirweight = 0.8)
This function determines whether a particular community is nested within any other communities.
getNestedHierarchies(x, clusid = 1, verbose = TRUE, plot = TRUE, ids = FALSE)
getNestedHierarchies(x, clusid = 1, verbose = TRUE, plot = TRUE, ids = FALSE)
x |
An object of class |
clusid |
An integer value indicating the community ID whose nesting structure will be tested. Defaults to 1. |
verbose |
Logical, whether to display a warning that a particular community is not nested in any other communities on the screen. Defaults to FALSE. |
plot |
Logical, whether to plot a graph layout of the nested community. |
ids |
Logical, whether to return only the community IDs that the community is nested in, or the node names also. Defaults to FALSE. |
Either a list of character vectors, each giving the nodes that the community is nested in, or an integer vector of community IDs that the community is nested in.
Alex T. Kalinka [email protected]
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Determine if community 1 is nested in any other communities. getNestedHierarchies(lc, clusid = 1)
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Determine if community 1 is nested in any other communities. getNestedHierarchies(lc, clusid = 1)
This function returns node names that belong to sets of communities.
getNodesIn(x, clusterids = 1, type = "names")
getNodesIn(x, clusterids = 1, type = "names")
x |
An object of class |
clusterids |
An integer vector of community IDs. Defaults to community 1. |
type |
A character string specifying how nodes are returned. Can be one of |
A character vector of node names (if type is "names"
) or a numerical vector of node indices (if type is "indices"
).
Alex T. Kalinka [email protected]
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Get nodes from community 1. getNodesIn(lc)
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Get nodes from community 1. getNodesIn(lc)
This function generates communities based on the OCG algorithm.
getOCG.clusters(network, init.class.sys = 3, max.class.card = 0, cent.class.sys = 1, min.class = 2, verbose = TRUE, keep.out = FALSE)
getOCG.clusters(network, init.class.sys = 3, max.class.card = 0, cent.class.sys = 1, min.class = 2, verbose = TRUE, keep.out = FALSE)
network |
Either a character string naming the file containing the network as an edge list, or a data frame/matrix object containing the edge list. |
init.class.sys |
An integer number specifying the Initial Class System: 1 - Maximal Cliques, 2 - Edges, or 3 - Centered Cliques. Defaults to 3. |
max.class.card |
An integer number specifying the maximum allowed class cardinality. Defaults to 0, which indicates no constraint. |
cent.class.sys |
A binary value indicating the choice of class system for centered cliques: 0 - Final class system, needs the expected minimum number of clusters and the maximum caldinality of the final clusters, or 1 - the class system that maximizes modularity. Defaults to 1. |
min.class |
An integer number specifying the minimum number of expected classes. Defaults to 2. |
verbose |
Logical, whether to display progress of the algorithm to the screen. Defaults to TRUE. |
keep.out |
Logical, whether to keep the OCG partition intermediate file on disk or not. Defaults to FALSE. |
An object of class OCG
, which is a list containing the following elements:
numbers |
An integer vector with the number of edges, nodes, and communities. |
modularity |
An integer number specifying the modularity of the network. |
Q |
A real number specifying the value of Q generated by the OCG algorithm. |
nodeclusters |
A data frame consisting of 2 columns; the first contains node names, and the second contains single community IDs for each node. All communities and their nodes are represented, but not necessarily all nodes. |
numclusters |
A named integer vector. Names are node names and integer values are the number of communities to which each node belongs. |
igraph |
An object of class |
edgelist |
A character matrix with 2 columns containing the nodes that interact with each other. |
clustsizes |
A named integer vector. Names are community IDs and integer values indicate the number of nodes that belong in each community. |
For optimal results, the input network must contain at least one connected component (a subgraph in which any two vertices are connected by a path, which is not connected to additional vertices in the supergraph).
Alain Guenoche (main algorithm), and ported into R by Alex T. Kalinka [email protected]
Becker, E., Robisson, B., Chapple, C.E., Guenoche, A. and Brun, C. (2012) Multifunctional proteins revealed by overlapping clustering in protein interaction network. Bioinformatics 28, 84-90.
## Generate graph and extract OCG communities. g <- swiss[,3:4] oc <- getOCG.clusters(g)
## Generate graph and extract OCG communities. g <- swiss[,3:4] oc <- getOCG.clusters(g)
This function returns vectors of node sizes or edge widths for use in plot.linkcomm
.
graph.feature(x, type = "nodes", clusterids = 1:length(x$clusters), nodes = NULL, indices, features, default = 15, showall = FALSE)
graph.feature(x, type = "nodes", clusterids = 1:length(x$clusters), nodes = NULL, indices, features, default = 15, showall = FALSE)
x |
An object of class |
type |
A character string specifying either |
clusterids |
An integer vector of community IDs that will be plotted. Defaults to all communities. |
nodes |
A character vector specifying node(s) that will be plotted. Overrides |
indices |
An integer vector specifying the indices of the nodes or edges that will be given specific size or width values. See |
features |
An integer vector specifying the node or edge sizes for the nodes or edges that are to be changed. If there is a single value then this will be applied to all nodes or edges specified in |
default |
An integer value specifying the node size or edge width that all nodes or edges not specified by |
showall |
Logical, whether edges that don't belong to communities will also be plotted or not. Defaults to FALSE. |
A named integer vector of node sizes or edge widths. The names will be either node names or edge indices.
Alex T. Kalinka [email protected]
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
plotLinkCommGraph
, getNodesIn
, getEdgesIn
, vignette(topic = "linkcomm", package = "linkcomm")
.
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Make node size vector for all nodes that belong to community 1. graph.feature(lc, indices = getNodesIn(lc, type = "indices"), features = 20, default = 5) ## Make edge width vector for all edges that belong to community 1. graph.feature(lc, type = "edges", indices = getEdgesIn(lc), features = 5, default = 1)
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Make node size vector for all nodes that belong to community 1. graph.feature(lc, indices = getNodesIn(lc, type = "indices"), features = 20, default = 5) ## Make edge width vector for all edges that belong to community 1. graph.feature(lc, type = "edges", indices = getEdgesIn(lc), features = 5, default = 1)
A set of 864 human proteins involved in 999 interactions.
human_pp
human_pp
Data frame with 2 columns.
Becker, E., Robisson, B., Chapple, C.E., Guenoche, A. and Brun, C. (2012) Multifunctional proteins revealed by overlapping clustering in protein interaction network. Bioinformatics 28, 84-90.
This function converts a character string edgelist into an integer edgelist.
integer.edgelist(network)
integer.edgelist(network)
network |
An edge list, which is a matrix or data frame with 2 or 3 columns. The first 2 columns contain the nodes that interact with each other, which can be character strings or integer values. The optional third column is a numerical vector of weights for each edge, which is stripped from the output. |
A list containing the following components:
edges |
A matrix with two columns containing the integer edgelist. |
nodes |
A named integer vector mapping node integer IDs to their character string equivalents. |
Alex T. Kalinka [email protected]
## Generate graph and convert into an integer edgelist. g <- data.frame(letters[1:10],letters[6:15]) gi <- integer.edgelist(g)
## Generate graph and convert into an integer edgelist. g <- data.frame(letters[1:10],letters[6:15]) gi <- integer.edgelist(g)
A social network of friendships between 34 members of a karate club at a US university in the 1970s (Zachary 1977).
karate
karate
Data frame with 2 columns.
https://github.com/gephi/gephi/wiki/Datasets
Zachary, W. W. (1977). An information flow model for conflict and fission in small groups. Journal of Anthropological Research 33, 452-473.
This function returns the x-y coordinates for nodes in a Spencer circle together with community anchor positions.
layout.spencer.circle(x, clusterids = 1:x$numbers[3], verbose = TRUE, jitter = 0.2)
layout.spencer.circle(x, clusterids = 1:x$numbers[3], verbose = TRUE, jitter = 0.2)
x |
An object of class |
clusterids |
An integer vector of community IDs. Defaults to all communities. |
verbose |
Logical, whether to print the progress of the calculation to the screen. Defaults to TRUE. |
jitter |
A positive numerical value specifying the range (negative to positive) of random, uniformly distributed noise that will be added to nodes that have identical x-y coordinates. Defaults to 0.2. |
This algorithm anchors communities evenly around the circumference of a circle in their dendrogram order (to minimise crossing over of links) and positions nodes within the circle according to how many links they possess in each of the communities (Spencer, 2010). Thus, nodes that have links to a lot of communities will get pushed into the centre of the circle making this method well suited for representing ego networks where one or a small number of nodes belong to multiple communities.
A list with the following components:
nodes |
A numerical matrix with nodes as rows and with 2 columns; the first contains the x coordinates and the second the y coordinates. |
anchors |
A numerical matrix with communities as rows and with 2 columns of x and y coordinates. |
Alex T. Kalinka [email protected]
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
Spencer, R. (2010). http://scaledinnovation.com/analytics/communities/comlinks.html
plot.linkcomm
, plotLinkCommGraph
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Extract x-y coordinates for nodes in a Spencer circle. layout.spencer.circle(lc)
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Extract x-y coordinates for nodes in a Spencer circle. layout.spencer.circle(lc)
The co-appearance network for Les Miserables (Knuth 1993). Involves 252 interactions among 77 nodes.
lesmiserables
lesmiserables
Data frame with 2 columns.
https://github.com/gephi/gephi/wiki/Datasets
Knuth, D. E. (1993). The Stanford GraphBase: A Platform for Combinatorial Computing, Addison-Wesley, Reading, MA.
This function writes out a partition file which can be imported into the Cytoscape plug-in Clust&See.
linkcomm2clustnsee(x, file = "temp.cns", network.name = NULL)
linkcomm2clustnsee(x, file = "temp.cns", network.name = NULL)
x |
An object of class |
file |
A character string naming a Clust&See partition file (.cns extension). Defaults to |
network.name |
A character string providing a name for the network. This name must correspond to the file name of the network that will be imported into Cytoscape. If NULL, the object name, |
Cytoscape is an open source platform for complex-network analysis and visualization, and Clust&See (Spinelli et al. 2013) is a Cytoscape plug-in used for visualizing and manipulating the clusters produced by various network clustering algorithms.
Used for its side-effect of writing a Clust&See partition file to disk.
Alex T. Kalinka [email protected]
Becker, E. et al. (2012) Multifunctional proteins revealed by overlapping clustering in protein interaction network. Bioinformatics 28, 84-90.
Gambette, P. and Guenoche, A. (2011) Bootstrap clustering for graph partitioning. RAIRO-Operations Research 45, 339-352.
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
Shannon, P. et al. (2003) Cytoscape: A software environment for integrated models of biomolecular interaction networks. Genome Research 13, 2498-2504.
Spinelli, L. et al. (2013) Clust&See: a Cytoscape plugin for the identification, visualization, and manipulation of network clusters. BioSystems 113, 91-95.
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Write a partition file to disk. ## Not run: linkcomm2clustnsee(lc) ## End(Not run)
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Write a partition file to disk. ## Not run: linkcomm2clustnsee(lc) ## End(Not run)
This function writes out an edge attribute file for visualising the link communities in Cytoscape.
linkcomm2cytoscape(x, interaction = "pp", ea = "temp.ea")
linkcomm2cytoscape(x, interaction = "pp", ea = "temp.ea")
x |
An object of class |
interaction |
A character string indicating the type of interaction between nodes. Defaults to |
ea |
A character string indicating the file for writing the edge attributes. Defaults to |
Cytoscape is an open source platform for complex-network analysis and visualization (Shannon et al. 2003).
Used for its side-effect of writing an edge attribute file to disk.
Alex T. Kalinka [email protected]
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
Shannon, P. et al. (2003) Cytoscape: A software environment for integrated models of biomolecular interaction networks. Genome Research 13, 2498-2504.
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Write an edge attribute file to disk. ## Not run: linkcomm2cytoscape(lc) ## End(Not run)
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Write an edge attribute file to disk. ## Not run: linkcomm2cytoscape(lc) ## End(Not run)
This function calculates link densities for link communities.
LinkDensities(x, clusterids = 1:x$numbers[3])
LinkDensities(x, clusterids = 1:x$numbers[3])
x |
An object of class |
clusterids |
An integer vector of community IDs. Defaults to all communities. |
The link density of community i is
where is the number of edges in community i and
is the number of nodes in community i.
A named numerical vector, where the names are community IDs and the numbers are link densities.
Alex T. Kalinka [email protected]
Ahn, Y.Y., Bagrow, J.P., and Lehmann, S. (2010). Link communities reveal multiscale complexity in networks. Nature 466, 761-764.
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
plot.linkcomm
, plotLinkCommSummComm
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Calculate link densities. ld <- LinkDensities(lc)
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Calculate link densities. ld <- LinkDensities(lc)
This function returns meta-communities by hierarchically clustering link communities based on their number of shared nodes.
meta.communities(x, hcmethod = "ward.D", deepSplit = FALSE)
meta.communities(x, hcmethod = "ward.D", deepSplit = FALSE)
x |
An object of class |
hcmethod |
A character string naming the hierarchical clustering method to use. Can be one of |
deepSplit |
Logical or integer value from 0 to 4 indicating how fine-grained the clusters should be with larger values giving increased cluster structure. Defaults to FALSE. |
Extracting meta-communities allows the user to explore community relatedness and structure at higher levels. Community relatedness is calculated using the Jaccard coefficient and the number of nodes that community i and j share:
A hierarchical clustering dendrogram is generated based on the above distance metric and then an algorithm is used to automatically extract clusters (Langfelder et al. 2008). This function works best on large networks with a large number of link communities.
An object of class linkcomm
, which is a list containing the following components:
numbers |
An integer vector with the number of edges, nodes, and communities. |
hclust |
An object of class |
pdmax |
A numerical value indicating the height of the dendrogram at which the partition density is maximised. |
pdens |
A numerical matrix with 2 columns; the first is the heights at which clusters appear and the second is the partition density. |
nodeclusters |
A data frame consisting of 2 columns; the first contains node names, and the second contains single community IDs for each node. All communities and their nodes are represented, but not necessarily all nodes. |
clusters |
A list of integer vectors containing the link IDs that belong to each community. Community IDs are the numerical position of the communities in the list. |
edges |
A data frame with 3 columns; the first two contain nodes that interact with each other, and the third is an integer vector of community IDs indicating community membership for each link. |
numclusters |
A named integer vector. Names are node names and integer values are the number of communities to which each node belongs. |
clustsizes |
A named integer vector. Names are community IDs and integer values indicate the number of nodes that belong in each community. |
igraph |
An object of class |
edgelist |
A character matrix with 2 columns containing the nodes that interact with each other. |
directed |
Logical indicating whether the network is directed. |
bipartite |
Logical indicating whether the network is bi-partite. |
Alex T. Kalinka [email protected]
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
Langfelder, P., Zhang, B., and Horvath, S. (2008) Defining clusters from a hierarchical cluster tree: the Dynamic Tree Cut package for R. Bioinformatics 24, 719-720.
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Produce meta-communities. ## Not run: mc <- meta.communities(lc)
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Produce meta-communities. ## Not run: mc <- meta.communities(lc)
This function allows the user to extract link communities by cutting the dendrogram at a specified height.
newLinkCommsAt(x, cutat = 0.5)
newLinkCommsAt(x, cutat = 0.5)
x |
An object of class |
cutat |
A numerical value indicating the height at which to cut the dendrogram. Defaults to 0.5. |
Users may wish to explore the communities formed by cutting the dendrogram higher or lower than the maximum partition density height. After cutting at a new height, the pdmax
value in the resulting object will be set to the cutat
value used by the user, only to distinguish the new object from the one generated by the link communities algorithm (the global partition density maximum does not change).
An object of class linkcomm
, which is a list containing the following components:
numbers |
An integer vector with the number of edges, nodes, and communities. |
hclust |
An object of class |
pdmax |
A numerical value indicating the height of the dendrogram at which the partition density is maximised. |
pdens |
A numerical matrix with 2 columns; the first is the heights at which clusters appear and the second is the partition density. |
nodeclusters |
A data frame consisting of 2 columns; the first contains node names, and the second contains single community IDs for each node. All communities and their nodes are represented, but not necessarily all nodes. |
clusters |
A list of integer vectors containing the link IDs that belong to each community. Community IDs are the numerical position of the communities in the list. |
edges |
A data frame with 3 columns; the first two contain nodes that interact with each other, and the third is an integer vector of community IDs indicating community membership for each link. |
numclusters |
A named integer vector. Names are node names and integer values are the number of communities to which each node belongs. |
clustsizes |
A named integer vector. Names are community IDs and integer values indicate the number of nodes that belong in each community. |
igraph |
An object of class |
edgelist |
A character matrix with 2 columns containing the nodes that interact with each other. |
directed |
Logical indicating whether the network is directed. |
bipartite |
Logical indicating whether the network is bipartite. |
After cutting at a new height, the pdmax
value in the resulting object will be set to the cutat
value used by the user, only to distinguish the new object from the one generated by the link communities algorithm (the global partition density maximum does not change).
Alex T. Kalinka [email protected]
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## User defined communities. lc2 <- newLinkCommsAt(lc, cutat = 0.8)
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## User defined communities. lc2 <- newLinkCommsAt(lc, cutat = 0.8)
This function returns the number of edges node(s) contain in each community.
numberEdgesIn(x, clusterids = 1:x$numbers[3], nodes)
numberEdgesIn(x, clusterids = 1:x$numbers[3], nodes)
x |
An object of class |
clusterids |
An integer vector of community IDs. Defaults to all communities. |
nodes |
A character vector specifying node(s) for which edge membership should be returned. |
A named list of named integer vectors specifying the number of edges in each community a node belongs in. Names of the integer vectors are community IDs, and names of the list are node names.
Alex T. Kalinka [email protected]
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
## Generate graph and extract OCG communities. g <- swiss[,3:4] oc <- getOCG.clusters(g) ## Get edges from community 1. numberEdgesIn(oc, nodes = 1)
## Generate graph and extract OCG communities. g <- swiss[,3:4] oc <- getOCG.clusters(g) ## Get edges from community 1. numberEdgesIn(oc, nodes = 1)
This function returns link communities in the same order as in the hierarchical clustering dendrogram.
orderCommunities(x, clusterids = 1:x$numbers[3], verbose = TRUE)
orderCommunities(x, clusterids = 1:x$numbers[3], verbose = TRUE)
x |
An object of class |
clusterids |
An integer vector of community IDs. Defaults to all communities. |
verbose |
Logical, whether to print progress of the calculation to the screen. Defaults to TRUE. |
Ordering link communities according to the dendrogram can aid in visualization when plotting them as a Spencer circle because it minimses crossing over between links.
A list with the following components:
ordered |
A list of integer vectors. These are the ordered communities of links. |
clusids |
An integer vector of community IDs in their new order. |
Alex T. Kalinka [email protected]
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
plot.linkcomm
, plotLinkCommGraph
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Order communities according to the dendrogram. orderCommunities(lc)
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Order communities according to the dendrogram. orderCommunities(lc)
linkcomm
Plotting Function
This function plots various different linkcomm
graphs.
## S3 method for class 'linkcomm' plot(x, type = "", ...)
## S3 method for class 'linkcomm' plot(x, type = "", ...)
x |
An object of class |
type |
A character string specifying the type of plot. Can be one of |
... |
Additional arguments to be passed to |
"summary"
plots the dendrogram and partition density plot side-by-side;"members"
plots a community membership matrix;"graph"
plots a graph layout of the network with coloured link communities;"commsumm"
plots a bar graph or pie chart summarising community modularity or connectedness for each community;"dend"
plots a dendrogram with coloured link communities.
See the individual plotting functions for details of arguments that can be passed to plot.linkcomm
: plotLinkCommSumm
, plotLinkCommMembers
, plotLinkCommGraph
, plotLinkCommSummComm
, and plotLinkCommDend
.
Plots to the current device.
Alex T. Kalinka [email protected]
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
plotLinkCommSumm
, plotLinkCommMembers
, plotLinkCommGraph
, plotLinkCommSummComm
, plotLinkCommDend
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Plot a graph of link communities. plot(lc, type = "graph")
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Plot a graph of link communities. plot(lc, type = "graph")
OCG
Plotting Function
This function plots various different OCG
graphs.
## S3 method for class 'OCG' plot(x, type = "", ...)
## S3 method for class 'OCG' plot(x, type = "", ...)
x |
An object of class |
type |
A character string specifying the type of plot. Can be one of |
... |
Additional arguments to be passed to |
"members"
plots a community membership matrix;"graph"
plots a graph layout of the network with coloured link communities.
See the OCG
plotting function for details of arguments that can be passed to plot.OCG
: plotOCGraph
, plotLinkCommMembers
.
Plots to the current device.
Alex T. Kalinka [email protected]
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
plotOCGraph
, plotLinkCommMembers
## Generate graph and extract OCG communities. g <- swiss[,3:4] oc <- getOCG.clusters(g) ## Plot a graph of OCG clusters. plot(oc, type = "graph")
## Generate graph and extract OCG communities. g <- swiss[,3:4] oc <- getOCG.clusters(g) ## Plot a graph of OCG clusters. plot(oc, type = "graph")
This function is called by plot.linkcomm
to plot a dendrogram of coloured link communities.
plotLinkCommDend(x, col = TRUE, pal = brewer.pal(9, "Set1"), height = x$pdmax, right = FALSE, labels = FALSE, plotcut = TRUE, droptrivial = TRUE, leaflab = "none", verbose = TRUE, ...)
plotLinkCommDend(x, col = TRUE, pal = brewer.pal(9, "Set1"), height = x$pdmax, right = FALSE, labels = FALSE, plotcut = TRUE, droptrivial = TRUE, leaflab = "none", verbose = TRUE, ...)
x |
An object of class |
col |
Logical, whether to add community-specific colours. Defaults to TRUE. |
pal |
A character vector describing a colour palette to be used for colouring the communites in the dendrogram plot. Defaults to |
height |
A numerical value specifying the height at which the dendrogram is cut. Defaults to the maximum partition density height. |
right |
Logical, whether to orient the dendrogram to the right. Defaults to FALSE. |
labels |
Logical, whether to include labels in the dendrogram. Defaults to FALSE. |
plotcut |
Logical, whether to display a horizontal line where the dendrogram is cut. Defaults to TRUE. |
droptrivial |
Logical, whether to not colour communities of size 2. Defaults to TRUE. |
leaflab |
A character string describing the leaf labels on the dendrogram. Can be one of |
verbose |
Logical, whether to display the progress of colouring the dendrogram on screen. Defaults to TRUE. |
... |
Additional arguments to be passed to |
Here we describe the parameters for plotting coloured dendrograms using:plot(x, type = "dend")
A dendrogram plot.
Alex T. Kalinka [email protected]
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Plot a coloured dendrogram. plot(lc, type = "dend")
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Plot a coloured dendrogram. plot(lc, type = "dend")
This function is called by plot.linkcomm
to plot a graph layout of the link communities.
plotLinkCommGraph(x, clusterids = 1:length(x$clusters), nodes = NULL, layout = layout.fruchterman.reingold, pal = brewer.pal(7, "Set2"), random = TRUE, node.pies = TRUE, pie.local = TRUE, vertex.radius = 0.03, scale.vertices = 0.05, edge.color = NULL, vshape = "none", vsize = 15, ewidth = 3, margin = 0, vlabel.cex = 0.8, vlabel.color = "black", vlabel.family = "Helvetica", vertex.color = "palegoldenrod", vlabel = TRUE, col.nonclusters = "black", jitter = 0.2, circle = TRUE, printids = TRUE, cid.cex = 1, shownodesin = 0, showall = FALSE, verbose = TRUE, ...)
plotLinkCommGraph(x, clusterids = 1:length(x$clusters), nodes = NULL, layout = layout.fruchterman.reingold, pal = brewer.pal(7, "Set2"), random = TRUE, node.pies = TRUE, pie.local = TRUE, vertex.radius = 0.03, scale.vertices = 0.05, edge.color = NULL, vshape = "none", vsize = 15, ewidth = 3, margin = 0, vlabel.cex = 0.8, vlabel.color = "black", vlabel.family = "Helvetica", vertex.color = "palegoldenrod", vlabel = TRUE, col.nonclusters = "black", jitter = 0.2, circle = TRUE, printids = TRUE, cid.cex = 1, shownodesin = 0, showall = FALSE, verbose = TRUE, ...)
x |
An object of class |
clusterids |
An integer vector of community IDs. Defaults to all communities. |
nodes |
A character vector naming the nodes to be plotted. If NULL, then community IDs are used instead. Defaults to NULL. |
layout |
A character string or function identifying the layout algorithm to be used for positioning nodes in the graph. Defaults to |
pal |
A character vector describing a colour palette to be used for colouring the link communities in the graph. Defaults to |
random |
Logical, whether to randomise the link colours. Defaults to TRUE. |
node.pies |
Logical, whether to plot node pies showing as a pie chart the fraction of each node's edges which belong to each of its communities. Defaults to TRUE. |
pie.local |
Logical, whether to include pie segments for just the communities to which the chosen nodes belong, or for all communities. In the latter case, communities that are not present among the chosen nodes will appear as empty segments in the node pies. Will be ignored if node.pies is FALSE. Defaults to TRUE. |
vertex.radius |
A real number specifying the vertex radius. Defaults to 0.03. Will be ignored if node.pies is FALSE. |
scale.vertices |
A real number specifying the fraction of increase in vertex radius for each community membership. If NULL then all vertices are the same size. Defaults to 0.05. Will be ignored if node.pies is FALSE. |
edge.color |
A character string specifying the colour of edges. Defaults to |
vshape |
A character string specifying the shape of the nodes. Can be one of |
vsize |
An integer vector of node sizes. If there is a single value this will be used for all nodes. If there are multiple values, it must be the same length as the number of nodes in the network to be visualized. See |
ewidth |
An integer vector of edge widths. If there is a single value this will be used for all edges. If there are multiple values, it must be the same length as the number of edges in the network to be visualized. See |
margin |
A numerical value specifying the amount of empty space around the graph. Negative values will zoom into the graph. Defaults to 0. |
vlabel.cex |
A numerical value specifying the size of node labels. Defaults to 0.8. |
vlabel.color |
A character string specifying the color of node labels. Defaults to |
vlabel.family |
A character string specifying the font family for node labels. Defaults to |
vertex.color |
A character string specifying the colour of nodes. If this is a character vector then the colours will be recycled. Defaults to |
vlabel |
Logical, whether node labels are to be added. Defaults to TRUE. |
col.nonclusters |
A character string specifying the colour of edges that do not belong to any communities. Will only have an effect if |
jitter |
A numerical value specifying the range (negative to positive) of random noise that will be added to nodes that have identical x-y coordinates. Defaults to 0.2. Only used for Spencer circle layouts. |
circle |
Logical, whether to display a circle for a Spencer circle layout. Defaults to TRUE. |
printids |
Logical, whether to display community IDs at their anchor points around the Spencer circle. Defaults to TRUE. |
cid.cex |
A numerical value specifying the size of community IDs around the Spencer circle. Defaults to 1. |
shownodesin |
An integer value specifying the number of communities a node must belong to before it will be displayed. If 0 then all nodes are displayed. Defaults to 0. |
showall |
Logical, whether to display all links in the network regardless of whether they belong to communities or not. Defaults to FALSE. |
verbose |
Logical, whether to print the progress of the calculation to the screen. Defaults to TRUE. |
... |
Additional arguments to be passed to |
Here we describe the parameters for plotting link community graphs using:plot(x, type = "graph", layout = layout)
Various graph layouts are available:
"spencer.circle"
layout.random
layout.circle
layout.sphere
layout.fruchterman.reingold
layout.kamada.kawai
layout.spring
layout.reingold.tilford
layout.fruchterman.reingold.grid
layout.lgl
layout.graphopt
layout.mds
layout.svd
layout.norm
All of these, except the "spencer.circle"
, are described in more detail in the igraph
package. The "spencer.circle"
is described in layout.spencer.circle
.
A graph plot.
Alex T. Kalinka [email protected]
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
plot.linkcomm
, layout.spencer.circle
, graph.feature
, igraph.plotting
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Plot a graph of link communities. plot(lc, type = "graph") ## Plot a graph of link communities using a Spencer circle layout. plot(lc, type = "graph", layout = "spencer.circle")
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Plot a graph of link communities. plot(lc, type = "graph") ## Plot a graph of link communities using a Spencer circle layout. plot(lc, type = "graph", layout = "spencer.circle")
This function is called by plot.linkcomm
to plot a community membership matrix for the link communities.
plotLinkCommMembers(x, nodes = head(names(x$numclusters), 10), pal = brewer.pal(11, "Spectral"), shape = "rect", total = TRUE, fontsize = 11, nspace = 3.5, maxclusters = 20)
plotLinkCommMembers(x, nodes = head(names(x$numclusters), 10), pal = brewer.pal(11, "Spectral"), shape = "rect", total = TRUE, fontsize = 11, nspace = 3.5, maxclusters = 20)
x |
An object of class |
nodes |
A character vector specifying the node names that will be included in the plot. Defaults to the 10 nodes that belong to the most communities. |
pal |
A character vector describing a colour palette to be used for community-specific colouring. Defaults to |
shape |
A character string specifying the shape of matrix entries. Can be one of |
total |
Logical, whether to display the number of communities each node belongs to and the number of nodes in each community. Defaults to TRUE. |
fontsize |
A numerical value specifying font size for the node names. Defaults to 11. |
nspace |
A numerical value specifying how much space to leave at the left for fitting in node names. Defaults to 3.5. |
maxclusters |
An integer value specifying the maximum number of communities to display. Defaults to 20. |
A community membership matrix plot.
Alex T. Kalinka [email protected]
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Plot a community membership matrix. plot(lc, type = "members")
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Plot a community membership matrix. plot(lc, type = "members")
This function is called by plot.linkcomm
to plot a summary of the output of the linkcomm
algorithm.
plotLinkCommSumm(x, col = TRUE, pal = brewer.pal(9, "Set1"), right = TRUE, droptrivial = TRUE, verbose = TRUE, ...)
plotLinkCommSumm(x, col = TRUE, pal = brewer.pal(9, "Set1"), right = TRUE, droptrivial = TRUE, verbose = TRUE, ...)
x |
An object of class |
col |
Logical, whether to colour link communities in the dendrogram. Defaults to TRUE. |
pal |
A character vector describing a colour palette to be used for colouring the link community dendrogram. Defaults to |
right |
Logical, whether to orient the dendrogram to the right. Defaults to TRUE. |
droptrivial |
Logical, whether to not colour communities of size 2. Defaults to TRUE. |
... |
Additional arguments to be passed to |
verbose |
Logical, whether to display the progress of colouring the dendrogram on the screen. Defaults to TRUE. |
Here we describe the parameters for plotting link community summaries using:plot(x, type = "summary")
A summary plot of the output from the linkcomm
algorithm.
Alex T. Kalinka [email protected]
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Plot the modularity of the link communities. plot(lc, type = "summary")
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Plot the modularity of the link communities. plot(lc, type = "summary")
This function is called by plot.linkcomm
to plot either connectedness or modularity of individual link communities.
plotLinkCommSummComm(x, clusterids = 1:x$numbers[3], summary = "conn", pie = FALSE, col = TRUE, pal = brewer.pal(11, "Spectral"), random = FALSE, verbose = TRUE, ...)
plotLinkCommSummComm(x, clusterids = 1:x$numbers[3], summary = "conn", pie = FALSE, col = TRUE, pal = brewer.pal(11, "Spectral"), random = FALSE, verbose = TRUE, ...)
x |
An object of class |
clusterids |
An integer vector of community IDs. Defaults to all communities. |
summary |
A character string specifying the community summary. Can be one of |
pie |
Logical, whether to plot a pie graph. If FALSE, a bar plot is plotted. Defaults to FALSE. |
col |
Logical, whether to colour each community differently. Defaults to TRUE. |
pal |
A character vector describing a colour palette to be used for colouring the link communities. Defaults to |
random |
Logical, whether to randomise the link colours. Defaults to FALSE. |
verbose |
Logical, whether to print the progress of the calculation to the screen. Defaults to TRUE. |
... |
Additional arguments to be passed to |
Here we describe the parameters for plotting link community summaries using:plot(x, type = "commsumm", type = "mod")
A bar graph or pie chart.
Alex T. Kalinka [email protected]
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Plot the modularity of the link communities. plot(lc, type = "commsumm", summary = "mod")
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Plot the modularity of the link communities. plot(lc, type = "commsumm", summary = "mod")
This function is called by plot.OCG
to plot a graph layout of the OCG communities.
plotOCGraph(x, clusterids = 1:x$numbers[3], nodes = NULL, pie.local = TRUE, incident = TRUE, layout = layout.fruchterman.reingold, vertex.radius = 0.03, scale.vertices = 0.05, edge.color = "grey", vertex.label.color = "black", vertex.label.cex = 0.8, pal = brewer.pal(7,"Set2"), shownodesin = 0, vlabel = TRUE, random = TRUE, ...)
plotOCGraph(x, clusterids = 1:x$numbers[3], nodes = NULL, pie.local = TRUE, incident = TRUE, layout = layout.fruchterman.reingold, vertex.radius = 0.03, scale.vertices = 0.05, edge.color = "grey", vertex.label.color = "black", vertex.label.cex = 0.8, pal = brewer.pal(7,"Set2"), shownodesin = 0, vlabel = TRUE, random = TRUE, ...)
x |
An object of class |
clusterids |
An integer vector of community IDs. Defaults to all communities. |
nodes |
A character vector naming the nodes to be plotted. If NULL, then community IDs are used instead. Defaults to NULL. |
pie.local |
Logical, whether to include pie segments for just the communities to which the chosen nodes belong, or for all communities. In the latter case, communities that are not present among the chosen nodes will appear as empty segments in the node pies. Defaults to TRUE. |
incident |
Logical, whether to include just the communities of the named node(s), or the community membership of all nodes that interact with the named node(s). Defaults to TRUE. |
layout |
A character string or function identifying the layout algorithm to be used for positioning nodes in the graph. Defaults to |
vertex.radius |
A real number specifying the vertex radius. Defaults to 0.03. |
scale.vertices |
A real number specifying the fraction of increase in vertex radius for each community membership. If NULL then all vertices are the same size. Defaults to 0.05. |
edge.color |
A character string specifying the colour of edges. Defaults to |
vertex.label.color |
A character string specifying the color of node labels. Defaults to |
vertex.label.cex |
A numerical value specifying the size of the node labels. Defaults to 0.8. |
pal |
A character vector describing a colour palette to be used for colouring the link communities in the graph. Defaults to |
shownodesin |
An integer value specifying the number of communities a node must belong to before it will be displayed. If 0 then all nodes are displayed. Defaults to 0. |
vlabel |
Logical, whether node labels are to be added. Defaults to TRUE. |
random |
Logical, whether to randomise the link colours. Defaults to TRUE. |
... |
Additional arguments to be passed to |
Here we describe the parameters for plotting OCG community graphs using:plot(x, type = "graph", layout = layout)
Various graph layouts are available:
layout.random
layout.circle
layout.sphere
layout.fruchterman.reingold
layout.kamada.kawai
layout.spring
layout.reingold.tilford
layout.fruchterman.reingold.grid
layout.lgl
layout.graphopt
layout.mds
layout.svd
layout.norm
All of these are described in more detail in the igraph
package.
A graph plot.
Alex T. Kalinka [email protected]
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
## Generate graph and extract OCG communities. g <- swiss[,3:4] oc <- getOCG.clusters(g) ## Plot a graph of OCG communities. plot(oc, type = "graph")
## Generate graph and extract OCG communities. g <- swiss[,3:4] oc <- getOCG.clusters(g) ## Plot a graph of OCG communities. plot(oc, type = "graph")
A set of 56 yeast proteins involved in 651 interactions related to transcription (Yu et al. 2008).
pp_rnapol
pp_rnapol
Data frame with 2 columns.
http://interactome.dfci.harvard.edu
Yu, H., et al. (2008). High-quality binary protein interaction map of the yeast interactome network. Science 322, 104-110.
linkcomm
Object
This function prints summary statistics for a linkcomm
object to the screen.
## S3 method for class 'linkcomm' print(x, ...)
## S3 method for class 'linkcomm' print(x, ...)
x |
An object of class |
... |
Further arguments passed to or from other methods. |
Prints summary data to the screen.
Alex T. Kalinka [email protected]
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Print summary statistics to the screen. print(lc)
## Generate graph and extract link communities. g <- swiss[,3:4] lc <- getLinkCommunities(g) ## Print summary statistics to the screen. print(lc)
OCG
Object
This function prints summary statistics for an OCG
object to the screen.
## S3 method for class 'OCG' print(x, ...)
## S3 method for class 'OCG' print(x, ...)
x |
An object of class |
... |
Further arguments passed to or from other methods. |
Prints summary data to the screen.
Alex T. Kalinka [email protected]
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
## Generate graph and extract OCG communities. g <- swiss[,3:4] oc <- getOCG.clusters(g) ## Print summary statistics to the screen. print(oc)
## Generate graph and extract OCG communities. g <- swiss[,3:4] oc <- getOCG.clusters(g) ## Print summary statistics to the screen. print(oc)
This function reads in an OCG partition file and converts it into an OCG object for use in R.
read.OCG(file, elfile = NULL, verbose = FALSE, keep.out = FALSE)
read.OCG(file, elfile = NULL, verbose = FALSE, keep.out = FALSE)
file |
A character string naming the OCG partition file. |
elfile |
A character string naming the file containing the network that the OCG partition is based upon. |
verbose |
Logical, whether to print progress to the screen. Defaults to FALSE. |
keep.out |
Logical, whether to keep the intermediate files written when reading in the OCG partition. Defaults to FALSE. |
An object of class OCG
, which is a list containing the following elements:
numbers |
An integer vector with the number of edges, nodes, and communities. |
modularity |
An integer number specifying the modularity of the network. |
Q |
A real number specifying the value of Q generated by the OCG algorithm. |
nodeclusters |
A data frame consisting of 2 columns; the first contains node names, and the second contains single community IDs for each node. All communities and their nodes are represented, but not necessarily all nodes. |
numclusters |
A named integer vector. Names are node names and integer values are the number of communities to which each node belongs. |
igraph |
An object of class |
edgelist |
A character matrix with 2 columns containing the nodes that interact with each other. |
clustsizes |
A named integer vector. Names are community IDs and integer values indicate the number of nodes that belong in each community. |
Alex T. Kalinka [email protected]
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
## Read an OCG partition file into R. ## Not run: oc <- read.OCG(file = "OCG_partition.txt", elfile = "network.txt")
## Read an OCG partition file into R. ## Not run: oc <- read.OCG(file = "OCG_partition.txt", elfile = "network.txt")
A sample of 200 links from a Drosophila gene co-expression network illustrating the input required for a weighted network (Tomancak et al. 2007).
weighted
weighted
Data frame with 3 columns.
http://www.fruitfly.org/cgi-bin/ex/insitu.pl
Tomancak, P. et al. (2007). Global analysis of patterns of gene expression during Drosophila embryogenesis. Genome Biol 8, 145.1-145.34.
This function returns the community IDs of the communities to which one or more nodes belong.
which.communities(x, nodes)
which.communities(x, nodes)
x |
An object of class |
nodes |
A character vector specifying the nodes. |
An integer vector of community IDs.
Alex T. Kalinka [email protected]
Kalinka, A.T. and Tomancak, P. (2011). linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics 27, 2011-2012.
## Generate graph and extract OCG communities. g <- swiss[,3:4] oc <- getOCG.clusters(g) ## Get edges from community 1. which.communities(oc, nodes = 1)
## Generate graph and extract OCG communities. g <- swiss[,3:4] oc <- getOCG.clusters(g) ## Get edges from community 1. which.communities(oc, nodes = 1)