| autoplot.ackwards | R Documentation |
When what = "hierarchy" (default), renders the layered bass-ackwards
hierarchy as a ggplot2 diagram. Factors appear as labelled boxes arranged
in levels (level 1 at top, level k at bottom by default; set
direction = "horizontal" for a left-to-right layout). Between-level edges
below cut_show are hidden. Two aesthetics carry the edge information, each
explained by its own legend: sign (positive/negative) is shown by
sign_by (edge colour by default) and magnitude (|r|) by
magnitude_by (line thickness by default). No aesthetic is ever mapped
without a matching legend.
## S3 method for class 'ackwards'
autoplot(
object,
what = c("hierarchy", "fit"),
sign_by = c("color", "linetype", "both", "none"),
magnitude_by = c("linewidth", "none"),
cut_show = NULL,
color_pos = "#2166AC",
color_neg = "#D6604D",
color_edge = "black",
colour_pos = NULL,
colour_neg = NULL,
colour_edge = NULL,
node_width = 0.8,
node_height = 0.4,
min_sep = 1,
show_skip = NULL,
curvature = 0.2,
color_pruned = "grey80",
colour_pruned = NULL,
show_r = FALSE,
r_digits = 2L,
r_label_size = 2.5,
mono = FALSE,
edge_linewidth = NULL,
cut_strong = NULL,
direction = c("vertical", "horizontal"),
show_level_labels = TRUE,
level_label_size = 3,
node_labels = NULL,
primary_only = FALSE,
drop_pruned = FALSE,
compress_levels = FALSE,
show_arrows = TRUE,
legend = TRUE,
...
)
## S3 method for class 'ackwards'
plot(x, ...)
object |
An |
what |
One of |
sign_by |
How edge sign (positive vs negative correlation) is
encoded. One of |
magnitude_by |
How edge magnitude ( |
cut_show |
Edges with |
color_pos, colour_pos |
Colour for positive edges when |
color_neg, colour_neg |
Colour for negative edges when |
color_edge, colour_edge |
Single colour for all edges when |
node_width |
Width of factor boxes in layout units. Default |
node_height |
Height of factor boxes in layout units. Default |
min_sep |
Minimum horizontal separation between nodes; passed to
|
show_skip |
Whether to draw skip-level (non-adjacent) edges. |
curvature |
Curvature of skip-level edge arcs. Passed to
|
color_pruned, colour_pruned |
Fill colour for nodes flagged as
pruned/redundant. Default |
show_r |
Whether to label each drawn edge with its correlation
coefficient. Default |
r_digits |
Number of decimal places for edge labels when
|
r_label_size |
Font size for edge correlation labels when
|
mono |
Monochrome convenience wrapper. When |
edge_linewidth |
|
cut_strong |
Deprecated in M35 and
ignored (with a warning). Edge magnitude is now shown by |
direction |
Layout orientation. |
show_level_labels |
Whether to draw level axis labels
("1 factor", "2 factors", ...) to the left of the diagram. Default |
level_label_size |
Font size for level axis labels. Default |
node_labels |
A named character vector mapping factor IDs (e.g.
|
primary_only |
When |
drop_pruned |
When |
compress_levels |
When |
show_arrows |
When |
legend |
When |
... |
Ignored. |
x |
An |
When what = "fit", renders a two-panel line plot of per-level fit indices
(CFI/TLI in the top panel; RMSEA/SRMR in the bottom panel) with horizontal
reference lines at conventional Hu & Bentler (1999) thresholds. The anchor
level (k = 1, saturated and always fits perfectly) is excluded. Requires an
EFA or ESEM engine; returns an informative empty plot for PCA (which has no
model-fit indices).
Requires the ggplot2 package.
A ggplot object.
autoplot() returns a standard ggplot object, so save it with
ggplot2::ggsave():
p <- autoplot(x)
ggplot2::ggsave("hierarchy.png", p, width = 8, height = 6, dpi = 300)
ggsave() is not re-exported by ackwards (that would move
ggplot2 from Suggests into Imports); call it from ggplot2
directly. For a wide slide or poster, pair it with
direction = "horizontal".
ba_layout(), plot.ackwards()
if (requireNamespace("ggplot2", quietly = TRUE)) {
# sim16 has a known 1 -> 2 -> 4 hierarchy (continuous; pearson basis)
x <- ackwards(sim16, k_max = 5)
autoplot(x)
autoplot(x, color_pos = "steelblue")
# Encode sign by linetype instead of colour, or by both
autoplot(x, sign_by = "linetype")
autoplot(x, sign_by = "both")
# Left-to-right layout (wide slides / posters)
autoplot(x, direction = "horizontal")
# Per-level fit index chart (EFA or ESEM only)
x_efa <- ackwards(sim16, k_max = 5, engine = "efa")
autoplot(x_efa, what = "fit")
# Monochrome with correlation labels (for greyscale figures)
autoplot(x, mono = TRUE, show_r = TRUE)
# Custom node labels for the 5-factor level
autoplot(x, node_labels = c(m5f1 = "Factor A", m5f2 = "Factor B"))
# Primary links only -- clean hierarchy tree
autoplot(x, primary_only = TRUE)
# Forbes pruned view: omit redundant nodes, straight spanning arrows
xp <- ackwards(sim16, k_max = 5) |> prune("redundant")
autoplot(xp, drop_pruned = TRUE)
autoplot(xp, drop_pruned = TRUE, show_r = TRUE)
autoplot(xp, drop_pruned = TRUE, compress_levels = TRUE)
# Plain line ends without arrowheads
autoplot(x, show_arrows = FALSE)
# Uniform edge width (no |r| scaling)
autoplot(x, edge_linewidth = 0.5)
# Suppress legend
autoplot(x, legend = FALSE)
# Forbes (2023) publication style: black lines, uniform width, no arrowheads
autoplot(xp,
drop_pruned = TRUE,
color_pos = "black", color_neg = "black",
edge_linewidth = 0.6, show_arrows = FALSE, legend = FALSE
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.