Project-level instructions for AI coding agents working on this repository. GitHub Copilot Code Review, Copilot coding agent, Codex, and other AGENTS.md-aware tools read this file directly.
Package overview
ggstatsplot is an R package that creates ggplot2-based plots with statistical details included in the plots themselves. It serves as a visualization frontend for statsExpressions.
Architecture
Main functions (R/)
- Visualization functions:
ggbetweenstats(),ggwithinstats(),gghistostats(),ggdotplotstats(),ggscatterstats(),ggcorrmat(),ggpiestats(),ggbarstats(), andggcoefstats(). - Eight visualization functions have
grouped_*variants that repeat the same analysis across a grouping variable.ggcoefstats()does not. - Most statistical plot functions expose a
typeselector built around the package’s parametric, nonparametric, robust, and Bayesian vocabulary. Check the function documentation because the supported analyses vary.ggcoefstats()instead has model-specific controls such aseffectsize.typeandmeta.type. - Functions return
ggplotor patchwork-compatible plot objects with statistical annotations.
Key helper functions
-
extract_stats(): Extract statistical details from a ggstatsplot object. -
extract_subtitle(): Extract the expression in a plot subtitle. -
extract_caption(): Extract the expression in a plot caption. -
theme_ggstatsplot(): Default theme for plots. -
combine_plots(): Combine multiple plots using patchwork.
Dependencies
Core dependencies include ggplot2, statsExpressions, the tidyverse stack (dplyr, purrr, tidyr, and rlang), patchwork, paletteer, and the easystats ecosystem (insight, parameters, performance, datawizard, and correlation). Treat DESCRIPTION as the source of truth for dependency constraints and the minimum supported R version.
Developer workflow
Use the repository Makefile for routine package tasks:
make install_deps # Install dependencies declared in DESCRIPTION
make build # Install dependencies, then build the package tarball
make check # Build and run R CMD check --no-manual
make install # Build and install the package locally
make document # Build, install into .local-lib, and render README.Rmd
make lint # Run lintr::lint_package()
make format # Format R code with Air (air format .)
make hooks # Run all prek hooks on all files
make hooks_install # Install the prek Git hooks
make clean # Remove package build and check artifacts
make update_deps # Refresh dependency constraints (maintenance only)Validation gate
This is the single source of truth for the full local validation gate used by the repository prompts and skills:
If Air reports drift, run make format (or air format .), inspect the result, and rerun the check. Run make document when README.Rmd or generated README content changes. Run the narrowest relevant testthat file first, for example Rscript -e 'testthat::test_local(filter = "ggbetweenstats")'.
Versioning and changelog
- Development versions use a fourth-component
.9000suffix. - Keep the version in
DESCRIPTION,codemeta.json, and the firstNEWS.mdheading synchronized. - Record user-facing compatibility or behavior changes in
NEWS.md; omit routine dependency, formatting, lint, test, CI, and generated-file maintenance.
Testing
- The package uses
testthatedition 3 with parallel execution. -
make checkrunsR CMD check, including the tests; see the validation gate above for the full local gate. - Tests mirror the relevant source area, but helper and shared source files may be covered by broader test files rather than a one-to-one filename match.
- Plot output is covered by
vdiffrsnapshots usingexpect_doppelganger()aftervdiffris attached by the test helper. - Treat broad snapshot diffs after dependency updates as potentially renderer-specific. Before accepting them, compare the old and new dependency builds under the same R and graphics stack and verify whether rendered text, statistics, or geometry actually changed.
- If both dependency builds reproduce the same SVG changes, restore the repository snapshots instead of committing local renderer churn. Confirm legitimate baseline updates with CI-native output across supported platforms.
- The top-level test runner (
tests/testthat.R) executes package tests only on Linux or macOS to avoid maintaining Windows snapshot variants. - Snapshots live in
tests/testthat/_snaps/. A few plots usevariant =inexpect_doppelganger()for platform (darwin/,linux/) or R-version (r-4.7/) differences; add a variant only when the difference is confirmed renderer-specific. - Failing snapshot tests write
.new.svgfiles next to the baselines. Inspect them withtestthat::snapshot_review()in an interactive R session, then accept intentional changes withtestthat::snapshot_accept("ggbetweenstats/")or discard them withtestthat::snapshot_reject(). When local and CI renderers disagree, use the snapshot artifact that the R-CMD-check workflow uploads on failure. - Codecov requires 100% project and patch coverage.
When adding visual tests, use the repository’s existing style:
test_that("descriptive name", {
set.seed(123)
expect_doppelganger(
title = "descriptive-name",
fig = function_under_test(data = dataset, x = var1, y = var2)
)
})Code conventions
- Use
lintr(configured in.lintr) for linting and Air (configured inair.toml) for formatting. - Use snake_case for functions and variables.
- Use the base R pipe (
|>), not the magrittr pipe (%>%). - Set seeds before tests that use random or Bayesian computations.
- Use
skip_if_not_installed()for optional dependencies. - Suppress warnings only when a test intentionally exercises a warning-producing path.
Roxygen documentation
- Roxygen uses Markdown and the
pkgapiandroxyglobalsroclets configured inDESCRIPTION. - Use
@autoglobalfromroxyglobalswhere appropriate. -
pkgapiis not on CRAN; install it withpak::pak("r-lib/pkgapi")before regenerating documentation. - Shared documentation lives in two places.
man/rmd-fragments/*.Rmdare pulled into function docs by roxygen Markdown chunks such as```{r child="man/rmd-fragments/ggbetweenstats_graphics.Rmd"}.man/md-fragments/*.mdare included by vignettes with```{asis, file="../../man/md-fragments/reporting.md"}. The per-function articles invignettes/web_only/include the graphics tables fromman/rmd-fragments/the same way. Useasisfile chunks rather than knitrchild=in articles: pkgdown renders them from a temporary file, so relative child paths do not resolve. Edit the fragment, not the generated output. - After changing roxygen comments, run
Rscript -e 'roxygen2::roxygenise()'and commit the generatedNAMESPACE,man/*.Rd,API(frompkgapi), andR/globals.R(fromroxyglobals) changes. Do not edit generated files by hand. - Regenerate with the roxygen2 release recorded in
Config/roxygen2/version. A newer roxygen2 rewrites that field (and may reformatNAMESPACE); commit that bump deliberately, together with the regenerated output, rather than as incidental churn. - Several parameters are inherited from
statsExpressionsvia@inheritParams, so the generated.Rdtext depends on the installedstatsExpressions. Regenerate against thestatsExpressionsversion thatDESCRIPTIONrequires (its GitHub development version while it is listed underRemotes, otherwise its CRAN release), not an arbitrary local build. -
make documentrendersREADME.Rmd; it is not the roxygen regeneration command in this repository.
Common function parameters
-
data: Input data frame. -
x,y: Unquoted column names using tidy evaluation. -
type: Usually one of"parametric","nonparametric","robust", or"bayes"where supported. -
paired: Whether the design is paired or within-subjects. -
results.subtitle: Whether to show statistical results in the subtitle. -
centrality.plotting: Whether to show the centrality measure. -
bf.message: Whether to show the Bayes factor message in the caption. -
ggtheme: The ggplot2 theme to use. -
palette: A single"package::palette"string understood bypaletteer(default"ggthemes::gdoc").
Important patterns
Plot construction
Functions build plots layer by layer with ggplot2, add expressions returned by statsExpressions, and finish with theme_ggstatsplot() or another supplied theme.
Statistical analysis delegation
Statistical computation belongs in statsExpressions; plotting functions in this package should delegate to that backend rather than duplicate statistical logic.
Grouped functions
Grouped functions map the corresponding plotting function across groups and combine the results with patchwork. Follow the existing purrr and patchwork::wrap_plots() patterns.
Files to update together
When modifying a function, consider all relevant surfaces:
-
R/<function>.Ror its helper file. - The corresponding files under
tests/testthat/. - Generated
man/<function>.Rdafter roxygen regeneration. -
vignettes/web_only/<function>.Rmdwhen that vignette exists. -
NEWS.mdfor user-facing changes.
Repository skills
Task-specific instructions live in .agents/skills/. Read a skill only when the task matches it:
-
create-release: prepare, submit, resume, or publish a CRAN release. -
update-dependencies: update dependencies to their latest versions, change the minimum R version, or add, remove, or move a dependency. -
maintain-ci: change or debug workflows under.github/workflows/.
User-invoked prompts for other tasks (address-review.md and simplify-codebase.md) live in .github/prompts/. Keep each topic in exactly one place: AGENTS.md for every-session rules, a skill or a prompt for task-specific procedures.
