Skip to content

Infer annotation aesthetics from the active ggplot2 theme (#120)#451

Open
ishaan-arora-1 wants to merge 1 commit intostan-dev:masterfrom
ishaan-arora-1:fix/theme-aware-annotations-120
Open

Infer annotation aesthetics from the active ggplot2 theme (#120)#451
ishaan-arora-1 wants to merge 1 commit intostan-dev:masterfrom
ishaan-arora-1:fix/theme-aware-annotations-120

Conversation

@ishaan-arora-1
Copy link
Contributor

Fixes #120.

Reference lines like the vertical zero-line in mcmc_intervals() and the rhat=1 line in mcmc_rhat() had hardcoded colors ("gray90", "gray") that didn't adapt when users switched ggplot2 themes. As @tjmahr pointed out in the issue, this makes them invisible or look wrong on themes like theme_grey() or dark themes.

Added an internal annotation_style() helper that reads the active theme's gridline color and linewidth to derive sensible reference line aesthetics. When gridlines are blank (bayesplot's default theme), it falls back to the previous gray90/0.5 defaults so existing plots look exactly the same.

Updated the four internal call sites in mcmc-intervals.R (3x vline_0) and mcmc-diagnostics.R (1x vline_at) to use the new helper.

Reference lines (e.g. the vertical zero-line in mcmc_intervals,
the rhat=1 line in mcmc_rhat) previously used hardcoded colors
like "gray90" that don't adapt when users switch ggplot2 themes.

Added an internal annotation_style() helper that reads the active
theme's gridline color and linewidth. When gridlines are present,
the reference line inherits their color at double the major
gridline width. When gridlines are blank (bayesplot's default),
it falls back to the previous gray90/0.5 defaults so existing
plots are unchanged.

Closes stan-dev#120
@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 43.47826% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.35%. Comparing base (c817061) to head (a0fd434).
⚠️ Report is 11 commits behind head on master.

Files with missing lines Patch % Lines
R/helpers-gg.R 26.66% 11 Missing ⚠️
R/mcmc-diagnostics.R 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #451      +/-   ##
==========================================
- Coverage   98.63%   98.35%   -0.29%     
==========================================
  Files          35       35              
  Lines        5860     5883      +23     
==========================================
+ Hits         5780     5786       +6     
- Misses         80       97      +17     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

infer annotation aesthetics from global theme

2 participants