cpCommunityGraph: Plotting Clique Percolation Community Network

View source: R/cpCommunityGraph.R

cpCommunityGraphR Documentation

Plotting Clique Percolation Community Network

Description

Function for plotting a network with nodes representing communities from clique percolation community detection and edges representing the number of shared nodes of the communities.

Usage

cpCommunityGraph(
  list.of.communities,
  node.size.method = c("proportional", "normal"),
  max.node.size = 10,
  ...
)

Arguments

list.of.communities

List object taken from results of cpAlgorithm function; see also cpAlgorithm

node.size.method

String indicating how node size is plotted ("proportional" or "normal"); see Details

max.node.size

Integer indicating size of the node representing the largest community, if node.size.method = "proportional"

...

any additional argument from qgraph; see also qgraph

Details

The function takes the results of cpAlgorithm (see also cpAlgorithm), that is, either the list.of.communities.numbers or the list.of.communities.labels and plots the community network. Each node represents a community. Edges connecting two nodes represent the number of shared nodes between the two communities.

The nodes can be plotted proportional to the sizes of the communities (node.size.method = "proportional"). The node representing the largest community is then plotted with the size specified in max.node.size. All other nodes are plotted relative to this largest node. Alternatively, all nodes can have the same size (node.size.method = "normal").

For the plotting, all isolated nodes will be ignored. If there are less than two communities in the list, plotting the network is useless. Therefore, an error is printed in this case.

Value

The function primarily plots the community network. Additionally, it returns a list with the weights matrix (community.weights.matrix) of the community network.

Author(s)

Jens Lange, lange.jens@outlook.com

Examples

## Example with fictitious data

# create qgraph object
W <- matrix(c(0,1,1,0,0,0,0,
              0,0,1,0,0,0,0,
              0,0,0,1,1,1,0,
              0,0,0,0,1,1,0,
              0,0,0,0,0,1,0,
              0,0,0,0,0,0,1,
              0,0,0,0,0,0,0), nrow = 7, ncol = 7, byrow = TRUE)
W <- Matrix::forceSymmetric(W)
W <- qgraph::qgraph(W)

# run clique percolation for unweighted networks
cp.results <- cpAlgorithm(W = W, k = 3, method = "unweighted")

# plot community network; proportional; maximum size is 7
cp.network1 <- cpCommunityGraph(cp.results$list.of.communities.numbers,
                                node.size.method = "proportional",
                                max.node.size = 7)
                                       
# plot community network; proportional; maximum size is 7
# change shape of nodes to triangle via qgraph argument
cp.network2 <- cpCommunityGraph(cp.results$list.of.communities.numbers,
                                node.size.method = "proportional",
                                max.node.size = 7,
                                shape = "triangle")
                                
## Example with Obama data set (see ?Obama)

# get data
data(Obama)

# estimate network
net <- qgraph::EBICglasso(qgraph::cor_auto(Obama), n = nrow(Obama))

# run clique percolation algorithm with specific k and I
cpk3I.16 <- cpAlgorithm(net, k = 3, I = 0.16, method = "weighted")

# plot community network; normal
Obama.network <- cpCommunityGraph(cpk3I.16$list.of.communities.numbers,
                                  node.size.method = "proportional",
                                  theme = "colorblind")


CliquePercolation documentation built on Nov. 10, 2022, 6:12 p.m.