plot_critical_edges: Visualize Central Graphs and Critical Edges

View source: R/plot_critical_edges.R

plot_critical_edgesR Documentation

Visualize Central Graphs and Critical Edges

Description

Produces a multi-panel figure summarising the output of identify_critical_links: one panel per population showing the weighted central graph, plus a final panel that highlights the critical edges on a chosen reference central graph. This is the canonical visualization of the BrainNetTest workflow and replaces the manual igraph plumbing required to build the same figure.

Usage

plot_critical_edges(
  populations,
  critical_links,
  communities = NULL,
  layout = NULL,
  central_graphs = NULL,
  reference = 1L,
  threshold = 0.5,
  edge_scale = 6,
  critical_color = "red",
  critical_width = 3,
  background_color = "grey80",
  background_width = 1,
  vertex_size = 12,
  vertex_label = TRUE,
  panel_titles = NULL,
  mfrow = NULL,
  ...
)

Arguments

populations

A named list of populations of adjacency matrices, as accepted by identify_critical_links. Used to compute the per-population central graphs unless central_graphs is supplied.

critical_links

The object returned by identify_critical_links. Its critical_edges component provides the edges to highlight in the final panel.

communities

Optional integer (or factor) vector of length n_nodes giving the community membership of every node. Used to color vertices consistently across panels. Default NULL (all vertices share the default igraph color).

layout

Optional layout for the graphs. Either an n_nodes x 2 numeric matrix of vertex coordinates (recommended, so that all panels share the same node positions) or an igraph layout function such as layout_with_fr. Default layout_in_circle.

central_graphs

Optional list of pre-computed central graphs (one per population). If NULL, they are computed via compute_central_graph.

reference

Either an integer index or a name selecting which population's central graph is used as the background of the critical-edges panel. Default 1L (the first population).

threshold

Numeric in [0, 1]. The reference central graph is binarised by > threshold for the critical-edges panel. Default 0.5.

edge_scale

Numeric multiplier applied to the central-graph edge weights to set edge.width in the per-population panels. Default 6.

critical_color, critical_width

Color and line width used to draw critical edges. Defaults "red" and 3.

background_color, background_width

Color and line width used to draw non-critical edges in the critical panel. Defaults "grey80" and 1.

vertex_size

Vertex size passed to plot.igraph. Default 12.

vertex_label

Logical. If TRUE (default) vertex indices are shown; otherwise vertex labels are suppressed.

panel_titles

Optional character vector of length length(populations) + 1 with custom panel titles. Default uses paste(names(populations), "Central Graph") followed by "Critical edges".

mfrow

Optional integer vector of length 2 giving the c(nrow, ncol) arrangement passed to par. By default a near-square grid is chosen automatically (e.g.\ a 2 x 2 grid for two populations, matching the standard Control / Patient / Critical layout).

...

Additional arguments forwarded to plot.igraph. Note that edge.width, vertex.color, vertex.size, vertex.label and layout are managed by this function and should not be passed via ....

Details

The first length(populations) panels show the weighted central graph of each population, with edge widths proportional to the central-graph weights. The final panel binarises the chosen reference central graph at threshold and overlays the critical edges returned by identify_critical_links() in critical_color. Critical edges that are absent from the binarised reference graph are added so that they remain visible.

The graphics state (par(mfrow, mar, oma)) is restored on exit.

Value

Invisibly returns NULL; called for its side effect of producing the multi-panel plot.

See Also

identify_critical_links, compute_central_graph, get_critical_nodes.

Examples


set.seed(123)
community_sizes <- c(4, 2, 3, 3, 5)
control <- generate_category_graphs(
  n_graphs = 50, n_nodes = 17, n_communities = 5,
  community_sizes = community_sizes,
  base_intra_prob = rep(0.70, 5), base_inter_prob = 0.05)
patient <- generate_category_graphs(
  n_graphs = 50, n_nodes = 17, n_communities = 5,
  community_sizes = community_sizes,
  base_intra_prob = c(0.40, 0.70, 0.70, 0.70, 0.70),
  base_inter_prob = 0.05)
populations <- list(Control = control, Patient = patient)
result <- identify_critical_links(populations, alpha = 0.05,
  method = "fisher", n_permutations = 200, seed = 1)
communities <- rep(seq_along(community_sizes), times = community_sizes)
plot_critical_edges(populations, result, communities = communities)


BrainNetTest documentation built on Dec. 3, 2026, 5:08 p.m.