Plots the difference between two networks (x - y) using splot. Positive differences (x > y) are shown in green, negative (x < y) in red. Optionally displays node-level differences (e.g., initial probabilities) as donut charts.
plot_difference(
x,
y = NULL,
i = NULL,
j = NULL,
pos_color = "#009900",
neg_color = "#C62828",
labels = NULL,
title = NULL,
inits_x = NULL,
inits_y = NULL,
show_inits = NULL,
donut_inner_ratio = 0.8,
force = FALSE,
combined = TRUE,
difference = FALSE,
...
)Invisibly returns a list with elements weights (the
element-wise difference matrix x - y) and inits (the
node-value difference, or NULL when no inits were available).
For the group_tna all-pairs path, a named list of such lists —
one element per pair, named "<group_i>_vs_<group_j>".
First network: matrix, cograph_network,
CographNetwork, tna, igraph, list-like object with
$weights, plain list of networks, or group_tna. For
group_tna with 2 groups, compares them directly. For more groups,
plots all pairwise comparisons (or specify i, j).
Second network: same type as x. Ignored if x is a list or
group_tna.
Index/name of first group when x is group_tna or a plain list.
NULL plots all pairs for a group_tna of more than two groups, and
selects the first element otherwise.
Index/name of second group when x is group_tna or a plain list.
NULL plots all pairs for a group_tna of more than two groups, and
selects the second element otherwise.
Color for positive differences (x > y). Default "#009900" (green).
Color for negative differences (x < y). Default "#C62828" (red).
Node labels. NULL uses rownames or defaults.
Plot title. NULL for auto-generated title.
Node values for x (e.g., initial probabilities). NULL to auto-extract from tna.
Node values for y. NULL to auto-extract from tna.
Logical: show node differences as donuts? Default
NULL, which shows them when inits are available for both networks.
Inner radius ratio for donut (0-1). Default 0.8.
Logical: force plotting when more than 4 groups (many comparisons). Default FALSE.
Logical: when TRUE (default) and x is a multi-group
input that triggers all-pairs plotting, lay panels out in an internal
grid via graphics::par(mfrow=...). Set to FALSE to draw into a
layout the caller has already configured (e.g. via
panel_layout()). Has no effect for the single-pair path.
Logical. If TRUE, x is treated as an
already-subtracted difference network (no y needed). A
tna_comparison object (from tna::compare()) is detected
automatically and its $difference_matrix is used.
Additional arguments passed to splot().
The function computes element-wise subtraction of the weight matrices. Edge colors indicate direction of difference:
Green edges: x has higher weight than y
Red edges: y has higher weight than x
When initial probabilities (inits) are provided or extracted from tna objects, nodes display donut charts showing the absolute difference, colored by direction:
Green donut: x has higher initial probability
Red donut: y has higher initial probability
For lists of networks (e.g., group_tna), specify which elements to compare using i and j parameters.
plot_compare, a first-class alias of this function
kept for the tna integration. plot_difference() is the
preferred name.
set.seed(42)
m1 <- matrix(runif(25), 5, 5)
m2 <- matrix(runif(25), 5, 5)
rownames(m1) <- colnames(m1) <- LETTERS[1:5]
rownames(m2) <- colnames(m2) <- LETTERS[1:5]
plot_difference(m1, m2)
# With node-level differences
plot_difference(m1, m2,
inits_x = c(.3, .2, .2, .15, .15),
inits_y = c(.1, .4, .2, .2, .1))
Run the code above in your browser using DataLab