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.
1 2 3 4 5 6
List object taken from results of cpAlgorithm function; see also cpAlgorithm
String indicating how node size is plotted (
Integer indicating size of the node representing the
largest community, if
any additional argument from qgraph; see also qgraph
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.
The function primarily plots the community network. Additionally, it returns a list with
the weights matrix (
community.weights.matrix) of the community network.
Jens Lange, email@example.com
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
## 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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.