View source: R/plot_net_group.R
| plot_net_group | R Documentation |
Creates a faceted ggplot comparing two group networks (e.g., female vs male) with nodes colored by domain, R2 progress rings, gradient-colored edges, and optional abbreviated labels with a legend mapping.
plot_net_group(
mat1,
mat2,
r2_1,
r2_2,
group_names = c("Femenino", "Masculino"),
labels = colnames(mat1),
short_labels = NULL,
full_labels = NULL,
groups_list = NULL,
group_cols = NULL,
palette = "Darjeeling1",
node_radius = 0.2,
node_label_size = NULL,
ring_offset = 0.045,
ring_stroke = 2.4,
ring_progress_col = "black",
edge_min = 0,
lwd_range = c(0.4, 4.5),
alpha_range = c(0.15, 1),
edge_color_pos = NULL,
edge_color_neg = NULL,
edge_curvature = 0,
show_edge_values = TRUE,
edge_label_digits = 2,
edge_label_size = 3.2,
edge_label_offset = 0.05,
edge_label_bg = TRUE,
edge_label_bg_fill = "white",
edge_label_bg_alpha = 0.9,
show_R2_text = TRUE,
R2_text_size = NULL,
R2_text_color = "grey30",
R2_digits = 2,
R2_position = "below",
title = NULL,
subtitle = NULL,
caption = "default"
)
mat1 |
Adjacency matrix for the first group. |
mat2 |
Adjacency matrix for the second group. |
r2_1 |
Numeric vector of R2 values for the first group. |
r2_2 |
Numeric vector of R2 values for the second group. |
group_names |
Character vector of length 2 with facet labels (default: c("Femenino","Masculino")). |
labels |
Character vector of node labels (default: colnames of mat1). |
short_labels |
Optional character vector of abbreviations displayed inside nodes. |
full_labels |
Optional character vector of full names for the caption legend. |
groups_list |
Named list mapping domain names to node indices. |
group_cols |
Named character vector of colors per domain. |
palette |
Wes Anderson palette used when |
node_radius |
Numeric radius of node circles. |
node_label_size |
Text size for node labels (NULL = auto). |
ring_offset |
Gap between node circle and R2 ring. |
ring_stroke |
Line width of the R2 ring. |
ring_progress_col |
Color of the R2 progress arc. |
edge_min |
Minimum absolute edge weight to display. |
lwd_range |
Numeric vector of length 2: min and max line widths. |
alpha_range |
Numeric vector of length 2: min and max alpha for edges. |
edge_color_pos |
Color for the strongest positive edge. |
edge_color_neg |
Color for the strongest negative edge. |
edge_curvature |
Curvature of edges (0 = straight). |
show_edge_values |
Logical; show edge weight labels? |
edge_label_digits |
Number of decimal digits for edge labels. |
edge_label_size |
Text size for edge labels. |
edge_label_offset |
Perpendicular offset for edge labels. |
edge_label_bg |
Logical; use background box for edge labels? |
edge_label_bg_fill |
Fill color of the edge label background. |
edge_label_bg_alpha |
Alpha of the edge label background. |
show_R2_text |
Logical; show R2 numeric text near nodes? |
R2_text_size |
Text size for R2 labels (NULL = auto). |
R2_text_color |
Color for R2 labels. |
R2_digits |
Decimal digits for R2 labels. |
R2_position |
Position of R2 text: "below", "above", "right", "left". |
title |
Optional plot title. |
subtitle |
Optional plot subtitle. |
caption |
Caption text. '"default"' explains the R2 ring; 'NULL' removes the caption. |
A ggplot object.
set.seed(123)
n <- 300
f1 <- rnorm(n)
f2 <- 0.3 * f1 + rnorm(n)
items <- data.frame(
sapply(1:4, function(i) 0.7 * f1 + rnorm(n, 0, 0.7)),
sapply(1:4, function(i) 0.7 * f2 + rnorm(n, 0, 0.7))
)
names(items) <- c(paste0("A", 1:4), paste0("B", 1:4))
sex <- rep(c("Female", "Male"), each = n / 2)
net_f <- bootnet::estimateNetwork(items[sex == "Female", ], default = "EBICglasso")
net_m <- bootnet::estimateNetwork(items[sex == "Male", ], default = "EBICglasso")
r2_f <- mgm_error_metrics(items[sex == "Female", ], type = rep("g", 8),
level = rep(1, 8))$R2
r2_m <- mgm_error_metrics(items[sex == "Male", ], type = rep("g", 8),
level = rep(1, 8))$R2
plot_net_group(
mat1 = net_f$graph, mat2 = net_m$graph,
r2_1 = r2_f, r2_2 = r2_m,
group_names = c("Female", "Male"),
groups_list = list(Anxiety = 1:4, Depression = 5:8)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.