plot_ridges()
View source ↗On this page
Draw the observed and the fitted survey length compositions of each time step as ridgelines, in two panels side by side.
Usage
plot_ridges(
model_result,
ridges_alpha = 0.8,
ridges_scale = NULL,
palette = NULL,
title = NULL,
xlab = NULL,
ylab = NULL,
font_family = NULL,
title_size = NULL,
axis_title_size = NULL,
axis_text_size = NULL,
strip_text_size = NULL,
legend_text_size = NULL,
x_breaks = NULL,
base_theme = NULL,
title_hjust = NULL
)
Arguments
| Argument | Default | Description |
|---|---|---|
model_result | required | A fit from |
ridges_alpha | 0.8 | Numeric. Transparency of the ridges. Default 0.8. |
ridges_scale | NULL | One finite positive number or NULL. Multiplier of the ridge height. NULL (default) scales the ridges so that the tallest peak is 0.8 of the distance between two time steps; time steps with a single observed length bin do not set this scale. Increase it for taller ridges and decrease it for flatter ones, for example when many length bins make each proportion small. |
palette | NULL | Character, character vector or NULL. Fill colors of the ridges, ordered by time. NULL (default) follows the global palette, giving a gradient from light blue to dark blue under the default palette (the same as |
title | NULL | Character, FALSE or NULL. One title for the whole figure. NULL (default) uses the global |
xlab | NULL | Character or NULL. Label of the x axis. NULL uses the global theme setting. |
ylab | NULL | Character or NULL. Label of the y axis. NULL uses the global theme setting. |
font_family | NULL | Character or NULL. Font family of the text, which must be installed on the computer. NULL uses the global theme setting (default "sans"). |
title_size | NULL | Numeric or NULL. Size of the plot title in pt. NULL uses the global theme setting (default 14). |
axis_title_size | NULL | Numeric or NULL. Size of the axis titles in pt. NULL uses the global theme setting (default 12). |
axis_text_size | NULL | Numeric or NULL. Size of the axis tick labels in pt. NULL uses the global theme setting (default 10). |
strip_text_size | NULL | Numeric or NULL. Size of the panel labels in pt. NULL uses the global theme setting (default 10). |
legend_text_size | NULL | Numeric or NULL. Size of the legend text in pt. NULL uses the global theme setting (default 10). |
x_breaks | NULL | Numeric vector or NULL. Positions of the x-axis breaks. NULL inherits the global x_breaks setting when at least one of its values lies on this axis; otherwise the breaks are chosen automatically. |
base_theme | NULL | Character or NULL. Name of the base ggplot2 theme, such as "bw", "minimal" or "theme_bw". NULL uses the global theme setting. Letter case does not matter. |
title_hjust | NULL | Numeric or NULL. Horizontal position of the title, 0 for left, 0.5 for centered and 1 for right. NULL uses the global theme setting. |
Value
A patchwork object holding the observed panel and the fitted panel, which can be saved with acl_save_plot(). Extract a panel with p[[1]] or p[[2]].
Details
The left panel shows the observed and the right panel the fitted survey length composition of each time step; each composition is normalized to sum to 1 within its time step. Only positive observations count. Missing values and zeros excluded from the fit stay missing, and a time step without observations has no observed ridge. The observed composition of a time step is taken over its observed length bins and the fitted composition over all length bins, so the two panels compare the position and spread of each distribution, not the exact heights. A time step with a single observed length bin has an observed composition of 1 by construction; it is drawn as a point at the height of the tallest ridge and does not set the automatic height. Missing or excluded length bins break the observed outline and fill, and an isolated observed length bin is drawn as a point at its scaled composition height.
Both panels cover the full length range of the model, also when the shortest or longest length bins or all observations are missing, and they share the time positions, the vertical range and the time colors. Custom x_breaks and the global x_expand apply to both panels. The time axis shows whole years for annual fits ("2000") and quarters for quarterly fits ("2000 Q2"); other time steps keep their decimal labels.
The default fill gradient follows time order, from light to dark blue under the default palette and viridis under any other palette, including that of the "classic" style. Brewer palettes such as "spectral" also work with two time steps. The figure has one title, from title or the global ridges title, and the two panels keep their own titles.
A fit that keeps observations and its fitted report needs no live TMB object and can be plotted after obj is removed; a fit without observations takes them from the data of its TMB object obj. Compositions are normalized on the log scale, so very large or small finite log predictions are drawn; nonfinite predictions stop with an error.
Additional details from R help
title is the title of the whole figure. The two panels keep
their own titles, from the global CatL_obs_length and
CatL_est_length keys, so that observed and fitted panels stay
labelled when the figure title is removed.
Examples
Run the setup before the example. Fitting examples require an R-compatible C++ toolchain; simulation and export examples may write files.
Example setup
library(ALSCL)
library(ggplot2)
library(patchwork)
data("YTF_example")
x <- YTF_example
inputs <- x[c("data.CatL", "data.wgt", "data.mat")]
dat <- x$data.CatL
a <- run_acl(x, silent = TRUE)
b <- run_alscl(x, silent = TRUE)
# Use objects defined above
plot_ridges(b)

plot_ridges(b)