| er_style_data | R Documentation |
Builder functions for the data layer (er_plot_add_data()), drawing raw
observations either as an overlay on the main panel or as separate
boxplot/jitter panels.
er_style_data_boxjitter(
data,
config,
stratify,
exposure,
response,
strata,
theme,
box_width = 0.6,
box_alpha = 0.4,
show_outliers = FALSE,
jitter_height = NULL,
jitter_size = 1,
jitter_alpha = 0.6,
...
)
er_style_data_overlay(
data,
config,
stratify,
exposure,
response,
strata,
theme,
jitter_height = NULL,
alpha = 0.4,
point_size = 1,
...
)
er_style_data_hex(
data,
config,
stratify,
exposure,
response,
strata,
theme,
bins = 30,
alpha = 0.85,
...
)
data |
The original data frame. |
config |
Configuration for the specific plot. |
stratify |
Logical: whether to stratify. |
exposure |
Exposure variable. |
response |
Response variable. |
strata |
Stratification variable. |
theme |
Theme components. |
box_width |
Width of |
box_alpha |
Transparency of |
show_outliers |
Logical: whether |
jitter_height |
Vertical jitter applied to raw points. Defaults to
|
jitter_size |
Point size for |
jitter_alpha |
Transparency of |
... |
Additional named arguments forwarded from |
alpha |
Point transparency for |
point_size |
Point size for |
bins |
Number of hex bins for |
See er_style() for the shared builder interface these functions
implement.
A geom, or a list of geoms; see er_style().
All three builders draw raw observations, but differ in structural
family (see er_style_tag()'s layout) and which response types
they support:
er_style_data_overlay() (the default) – raw points, overlaid
directly on the main panel (layout = "overlay"). Any response
type.
er_style_data_hex() – a 2D hexbin density overlay on the main
panel instead of individual points (layout = "overlay"), useful
when there are too many points for er_style_data_overlay() to
stay legible. Requires the hexbin package.
er_style_data_boxjitter() – a boxplot + jitter panel stacked
below/above the main panel instead of an overlay
(layout = "panel"). Binary-response only.
All built-in data builders are also tagged layer = "plot_data", so
er_plot_add_data() errors if given a builder tagged for another
layer.
er_style_data_hex() defaults to a light-grey-to-navy ("grey90" to
"#132B43") fill gradient, so a cell's fill fades toward the panel
background as its count approaches zero rather than starting at
ggplot2's own default mid-intensity blue. Override it with
er_plot_theme(fill_continuous = ...).
Because its geoms cover the whole panel, er_style_data_hex() is
tagged er_style_tag(fn, draw_order = "background") (see er_style_tag()),
so it's drawn before the model/summary/quantile layers rather than on
top of them; its default alpha = 0.85 gives those layers a little
extra visibility through even a densely populated hex cell.
er_style(), er_style_tag()
if (requireNamespace("erglm", quietly = TRUE)) {
library(erglm)
mod2 <- erglm_model(ae2 ~ aucss + sex, erglm_data, family = binomial())
# er_style_data_overlay(): the default, raw points on the main panel
erglm_data |>
er_plot(aucss, ae2, stratify_by = sex) |>
er_plot_add_model(mod2) |>
er_plot_add_data(style = er_style_data_overlay) |>
plot()
# er_style_data_boxjitter(): binary-response only, boxplot + jitter
# panels above/below the main panel instead of an overlay
erglm_data |>
er_plot(aucss, ae2, stratify_by = sex) |>
er_plot_add_model(mod2) |>
er_plot_add_data(style = er_style_data_boxjitter) |>
plot()
# overriding a builder's own visual defaults, e.g. larger/more
# opaque points and a wider jitter
erglm_data |>
er_plot(aucss, ae2, stratify_by = sex) |>
er_plot_add_model(mod2) |>
er_plot_add_data(
style = er_style_data_overlay,
jitter_height = 0.1,
alpha = 0.7,
size = 2
) |>
plot()
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.