Skip to contents

A specialized function to plot network structures, overlaying community detection (clusters) via convex hulls and allowing for mapping of theoretical domains to node aesthetics. It utilizes ggplot2::ggplot() and ggforce::geom_mark_hull() for rendering.

Usage

plot_clusters(
  net,
  layout = "spring",
  original.categories = NA,
  pointsize = 10,
  concavity = 3,
  legend.title = "",
  labels = NA,
  labelsize = 3,
  radius = 0.04,
  shape = 21,
  outline = F,
  colored = F,
  alpha = 1,
  cluster.base = net,
  fill.colors = NA,
  show.clusters = T,
  ...
)

Arguments

net

Network produced by bootnet::estimateNetwork().

layout

Character string or matrix specifying the network layout. Passed to qgraph::qgraph(). Defaults to "spring".

original.categories

A data.frame with two columns, "label" (categories) and "L1" (nodes). Used for assigning nodes to theoretical domains.

pointsize

Numeric scalar or vector specifying node size(s). Defaults to 10.

concavity

Numeric value for the concavity of the cluster hulls. Passed to ggforce::geom_mark_hull(). Defaults to 3.

legend.title

Character string for the fill legend title. Defaults to "".

labels

Custom node labels, should be in order of the nodes in the net$graph. Defaults to NA.

labelsize

Numeric value specifying the size of node labels. Defaults to 3.

radius

Numeric value specifying the corner radius of cluster hulls. Passed to ggforce::geom_mark_hull(). Defaults to 0.04.

shape

Numeric value specifying the ggplot2::geom_point() shape for nodes. Defaults to 21.

outline

Logical. If TRUE, uses ggplot2::geom_label() to draw a box around text. If FALSE, uses ggplot2::geom_text(). Defaults to FALSE.

colored

Logical. If TRUE, edges are colored (e.g., red/blue for negative/positive). If FALSE, edge sign is represented by linetype. Defaults to FALSE.

alpha

Numeric value between 0 and 1 specifying edge transparency. Defaults to 1.

cluster.base

Network object to use for community detection. Defaults to the net argument.

fill.colors

Vector of character colors for the node fill aesthetic. If NA, defaults to a colorblind-friendly palette.

show.clusters

Logical. If TRUE, calculates communities and plots convex hulls around them. Defaults to TRUE.

...

Additional arguments passed to EGAnet::community.detection().

Value

A ggplot2::ggplot() object representing the network graph.

Examples

mtcars = datasets::mtcars
library(bootnet)
#> Loading required package: ggplot2
#> This is bootnet 1.9.1
#> For questions and issues, please see github.com/SachaEpskamp/bootnet.
library(EGAnet)
#> Error in library(EGAnet): there is no package called ‘EGAnet’

# Estimate network
network <- estimateNetwork(mtcars, default = "EBICglasso")
#> Estimating Network. Using package::function:
#>   - qgraph::EBICglasso for EBIC model selection
#>     - using glasso::glasso
#> Warning: A dense regularized network was selected (lambda < 0.1 * lambda.max). Recent work indicates a possible drop in specificity. Interpret the presence of the smallest edges with care. Setting threshold = TRUE will enforce higher specificity, at the cost of sensitivity.

# Plot with clusters
plot_clusters(network, layout = "spring", show.clusters = TRUE)
#> Error in loadNamespace(x): there is no package called ‘EGAnet’