View source: R/shift-distributions.R
| plot.shift_magnitude_comparison | R Documentation |
Draw one density panel from a compare_shift_magnitudes() result. By
default, the method reproduces the Berv et al. (2026) Supplementary Figure 5
scaling: each density integrates to that direction's observed frequency, so
panel height reflects both shift magnitude and relative abundance. Set
scale_by_frequency = FALSE for conventional unit-area densities.
## S3 method for class 'shift_magnitude_comparison'
plot(
x,
scale_by_frequency = TRUE,
density_args = list(),
colors = c(increase = "#377eb8", decrease = "#e41a1c"),
fill_alpha = 0.22,
lwd = 2,
xlim = NULL,
ylim = NULL,
xlab = NULL,
ylab = NULL,
main = NULL,
annotate = TRUE,
show_modes = TRUE,
show_sample_size = TRUE,
show_test_label = TRUE,
show_modal_ratio = TRUE,
legend = TRUE,
rug = FALSE,
mar = c(4.5, 4.5, 2.4, 0.8),
oma = c(0, 0, 0, 0),
...
)
x |
A single |
scale_by_frequency |
Logical; multiply each density by its observed increase/decrease frequency. |
density_args |
Optional named list of additional arguments passed to
|
colors |
Named colors for |
fill_alpha |
Alpha value for density fills. |
lwd |
Line width for density curves. |
xlim, ylim |
Optional axis limits. |
xlab, ylab, main |
Plot labels. |
annotate |
Logical; draw panel annotations. This is a master switch for
|
show_modes |
Logical; draw dashed vertical lines at the KDE modes for increase and decrease magnitudes. |
show_sample_size |
Logical; include increase/decrease sample sizes in
panel annotations when |
show_test_label |
Logical; include KS statistics and p-values in panel
annotations when |
show_modal_ratio |
Logical; include the back-transformed modal ratio in
panel annotations when |
legend |
Logical; draw an increase/decrease legend. |
rug |
Logical; add rugs for the transformed values. |
mar, oma |
Graphical margins passed to |
... |
Additional graphical parameters passed to |
Invisibly returns a list with the comparison object, summary tables, density estimates, and plot settings.
transitions <- data.frame(
rate_change = c("increase", "increase", "increase", "decrease", "decrease", "decrease"),
rate_delta = c(3, 4, 5, -1, -1.5, -2)
)
comparison <- compare_shift_magnitudes(transitions, ks_reps = 99)
plot(comparison)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.