Skip to contents

depictr is a single, consistent toolkit of plots that span the whole analysis workflow, from a first look at the data, through model estimates and predictions, to diagnostics, uncertainty and reporting. Every plotting function returns a ggplot2 object (Wickham, 2016) (or a patchwork for composite panels), so you can keep customising with the usual + syntax, and every plot shares one theme, one palette and one set of label conventions.

Five datasets to explore

The package ships with five reproducibly simulated datasets, each chosen to exercise a different family of plots. They are documented under their names (e.g. ?lexical_decision) and load with data():

  • lexical_decision: a counterbalanced, crossed reaction-time/accuracy experiment (participant, item, condition, modality, word frequency). For mixed models and the classification plots.
  • wellbeing_survey: a cross-sectional survey (life satisfaction, stress, sleep, income, age, ordered education, region) with informative missingness. For descriptives, correlations, regression and missing data.
  • crop_yield: a field trial with a genuine fertiliser-by-treatment interaction. For regression, scatter-trend and interaction plots.
  • clinical_trial: a two-arm trial with separating survival curves and a rare adverse-event outcome. For survival and imbalanced classification.
  • monthly_sales: two seasonal monthly series (indoor/outdoor). For the time-series plots.

A tour by task

Begin with the data. explore_bivariate() chooses a suitable plot for any pair of variables, here a scatter with a trend because both are numeric.

explore_bivariate(crop_yield, fertiliser, yield)

Turn next to the model. After fitting it, coefficient_plot() draws a forest plot of the estimates.

fit <- lm(yield ~ rainfall + fertiliser + soil_ph + treatment, data = crop_yield)
coefficient_plot(fit, order = "descending", title = "Drivers of crop yield")

To see what the model implies, effects_plot() traces the predicted response as one predictor varies.

effects_plot(fit, "fertiliser")

residual_diagnostics_plot() gathers the usual checks of the fit into one panel.

For uncertainty, posterior_plot() summarises posterior or simulation draws as a distribution per parameter. These are the real fixed-effect posterior draws from a Bayesian fit of the lexical-decision model, shipped with the package.

draws <- readRDS(system.file("extdata", "lexdec_draws.rds", package = "depictr"))
posterior_plot(draws[c("conditionunrelated", "modalityauditory",
                       "word_frequency")],
               labels = c(conditionunrelated = "condition",
                          modalityauditory = "modality",
                          word_frequency = "word frequency"),
               title = "Lexical-decision fixed effects (ms)")

The shared spine: tidy_estimates()

Most of the model functions rest on tidy_estimates(), which turns a model, or a data frame of pre-computed estimates, into one standard table. Because the plotting functions also accept that table, estimates from any source (Bayesian posteriors, bootstrap intervals, or figures taken from a paper) can be supplied directly.

tidy_estimates(fit)
#>                term     estimate    std.error     conf.low    conf.high
#> 1       (Intercept) -7.156372471 0.7307020339 -8.597465983 -5.715278960
#> 2          rainfall  0.003869765 0.0006025038  0.002681505  0.005058026
#> 3        fertiliser  0.011266582 0.0010906005  0.009115695  0.013417469
#> 4           soil_ph  1.030217728 0.1056219670  0.821909657  1.238525800
#> 5 treatmentenhanced  1.317044684 0.0978270830  1.124109715  1.509979654

A consistent, accessible look

theme_depictr(), depictr_palette() and scale_colour_depictr() style your own plots too:

library(ggplot2)
ggplot(crop_yield, aes(fertiliser, yield, colour = treatment)) +
  geom_point(alpha = 0.7) +
  scale_colour_depictr() +
  theme_depictr()

depictr_palette() returns the underlying hex colours directly, ready to feed scale_fill_manual() or a base-graphics col = argument:

depictr_palette(4)
#> [1] "#005b96" "#e69f00" "#009e73" "#d55e00"

The qualitative palette is based on the Okabe-Ito set (Okabe & Ito, 2008), which stays distinguishable under the common forms of colour-vision deficiency; sequential and diverging variants are available too. Preview them with:

palette_preview(type = "all")

palette_preview() can also simulate a colour-vision deficiency, so you can check a palette as a deuteranope (red-green) would see it:

palette_preview(cvd = "deutan")

Set the look once for a whole script with depictr_options() (base size, base family, brand and accent colours, or a custom palette), instead of passing the same arguments to every call. Called with no arguments it reports the current settings:

depictr_options()
#> $base_size
#> [1] 11
#> 
#> $base_family
#> [1] ""
#> 
#> $brand
#> [1] "#005b96"
#> 
#> $accent
#> [1] "#d55e00"
#> 
#> $reference
#> [1] "grey60"
#> 
#> $palette
#> NULL
#> 
#> $na_value
#> [1] "grey80"

Supplying arguments sets them for every later plot and returns the previous values, so you can put the look back afterwards:

old <- depictr_options(base_size = 13, accent = "#b3589a")
coefficient_plot(fit, title = "Set once, applied everywhere")

do.call(depictr_options, old)   # restore the previous settings

Where to next

The remaining articles go into each area in turn. vignette("exploring-data") covers distributions, categories, bivariate plots, scatter-plot matrices, correlations, missingness, outliers, summary tables and the estimation plots. vignette("model-estimates") is the flagship: forest plots, model comparison, predicted values, interactions, random effects, optimiser checks and the frequentist-over-Bayesian-posterior overlay. vignette("diagnostics-and-uncertainty") covers residuals, GLM-appropriate binned residuals, the classification suite (ROC, PR, gains, lift, calibration, thresholds) on an imbalanced outcome, and power curves. Two further articles, vignette("multivariate-and-survival") and vignette("time-series"), cover the remaining methods.

References

Okabe, M., & Ito, K. (2008). Color Universal Design (CUD): How to make figures and presentations that are friendly to colorblind people. https://jfly.uni-koeln.de/color/.
Wickham, H. (2016). ggplot2: Elegant graphics for data analysis (2nd ed.). Springer. https://doi.org/10.1007/978-3-319-24277-4