View source: R/er-plot-theme.R
| er_plot_theme | R Documentation |
Set axis/legend labels, plot titles/captions, axis limits, theme objects, discrete and continuous scale objects, formatters, legend key glyph, and relative panel heights. This does not change which variable is mapped to which aesthetic.
er_plot_theme(
object,
xlab = NULL,
ylab = NULL,
strata_lab = NULL,
title = NULL,
subtitle = NULL,
caption = NULL,
xlim = NULL,
ylim = NULL,
theme_base = NULL,
theme_extra = NULL,
color_discrete = NULL,
fill_discrete = NULL,
color_continuous = NULL,
fill_continuous = NULL,
format_p = NULL,
format_percent = NULL,
format_number = NULL,
draw_key = NULL,
dodge_width = NULL,
height_base = NULL,
height_data = NULL,
height_group = NULL
)
object |
Partially constructed plot (has S3 class |
xlab, ylab |
Exposure/response axis label (single string). |
strata_lab |
Stratification legend label (single string).
Errors if |
title, subtitle, caption |
Plot-level annotation text (single
strings), applied via |
xlim, ylim |
Exposure/response axis limits (length-2, increasing
numeric vectors, no |
theme_base |
A ggplot2 theme object (e.g. |
theme_extra |
A ggplot2 theme object (e.g. from |
color_discrete, fill_discrete |
A discrete ggplot2 scale object
(e.g. |
color_continuous, fill_continuous |
A continuous ggplot2 scale object
(e.g. |
format_p, format_percent, format_number |
Formatter functions
(typically from |
draw_key |
A key-glyph function (e.g. |
dodge_width |
Spacing between adjacent strata's horizontal offset in the quantile layer, as a fraction of the exposure range. A single positive number; see "Details". |
height_base, height_data, height_group |
Relative panel heights
(single positive numbers), for the base plot, data-layer panel(s),
and group-layer panel(s) respectively. Default to |
dodge_width is a stratification-layout setting used by
er_style_quantile_errorbar()/er_style_quantile_pointrange() (and
their _vlines variants) to separate strata horizontally within each
quantile bin. It belongs in er_plot_theme() because dodging is about
stratification layout, not an individual builder's visual style.
Defaults to 0.015 (set in er_plot()).
Every argument defaults to NULL, meaning "leave whatever was set
before unchanged". This allows repeated calls to er_plot_theme() to
update only the supplied fields, like ggplot2::theme(). There is no
implicit way to reset a field to the er_plot() default.
color_discrete/fill_discrete apply only when a layer's colour/
fill aesthetic is mapped to stratification. Their continuous
counterparts, color_continuous/fill_continuous, apply only when the
aesthetic is mapped to a continuous quantity such as density or a
continuous/count response value. If a custom builder adds its own scale,
supplying one of these four will add a second scale and let ggplot2
choose the later one.
theme_extra defaults to a panel border plus legend.position = "bottom". Supplying a new value fully replaces this default rather
than merging with it, so re-include the border/legend-position
settings too if you want to keep them alongside your own additions.
The input object, with the requested theme fields updated.
er_plot(), er_style()
if (requireNamespace("erglm", quietly = TRUE)) {
library(erglm)
mod <- erglm_model(ae1 ~ aucss, erglm_data, family = binomial())
# axis labels, a title, and a swapped-in theme
erglm_data |>
er_plot(aucss, ae1) |>
er_plot_add_model(mod) |>
er_plot_theme(
xlab = "AUC at steady state",
ylab = "P(adverse event)",
title = "Exposure-response for adverse events",
theme_base = ggplot2::theme_minimal()
) |>
plot()
# repeated calls accumulate: this only touches xlim/ylim, leaving
# the labels/title/theme set above unchanged
erglm_data |>
er_plot(aucss, ae1) |>
er_plot_add_model(mod) |>
er_plot_theme(xlab = "AUC at steady state") |>
er_plot_theme(xlim = c(0, 3000)) |>
plot()
# widening the stratum-dodge spacing in a stratified quantile layer
mod2 <- erglm_model(ae1 ~ aucss + sex, erglm_data, family = binomial())
erglm_data |>
er_plot(aucss, ae1, stratify_by = sex) |>
er_plot_add_model(mod2) |>
er_plot_add_quantiles() |>
er_plot_theme(dodge_width = 0.15, strata_lab = "Sex") |>
plot()
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.