Skip to content

Fix override.aes size to linewidth for linetype legend (#449)#450

Merged
jgabry merged 6 commits intostan-dev:masterfrom
ishaan-arora-1:fix/geom-function-and-override-aes-449
Mar 13, 2026
Merged

Fix override.aes size to linewidth for linetype legend (#449)#450
jgabry merged 6 commits intostan-dev:masterfrom
ishaan-arora-1:fix/geom-function-and-override-aes-449

Conversation

@ishaan-arora-1
Copy link
Contributor

@ishaan-arora-1 ishaan-arora-1 commented Mar 10, 2026

Fixes the override.aes in the linetype legend for mcmc_trace() divergence plots — changes size to linewidth, which is the correct aesthetic for line widths since ggplot2 3.4.0.

The stat_function -> geom_function change has been reverted per review feedback.

- overlay_function() now wraps geom_function() instead of the older
  stat_function(), matching modern ggplot2 conventions
- Use linewidth instead of size in override.aes for line-based legend
  keys in mcmc-traces.R and ppd-distributions.R
- Update documentation and tests accordingly

Closes stan-dev#449
@jgabry
Copy link
Member

jgabry commented Mar 10, 2026

Thanks. this seems like a change we should make but we have a failing test:

https://github.com/stan-dev/bayesplot/actions/runs/22910316067/job/66500925400?pr=450#step:7:1175

The override.aes change from size to linewidth affects the legend
key rendering, so these snapshots need to be regenerated.
@ishaan-arora-1
Copy link
Contributor Author

@jgabry only ubuntu fails, we can merge now right?

@codecov-commenter
Copy link

codecov-commenter commented Mar 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.55%. Comparing base (b1cb851) to head (64bd86c).
⚠️ Report is 10 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #450   +/-   ##
=======================================
  Coverage   98.55%   98.55%           
=======================================
  Files          35       35           
  Lines        5864     5864           
=======================================
  Hits         5779     5779           
  Misses         85       85           

☔ 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.

@jgabry
Copy link
Member

jgabry commented Mar 11, 2026

stat_function(), which has been superseded by geom_function() since ggplot2 3.3.0

Actually, I have a question about this. I just checked the doc for stat_function and it's not deprecated and it doesn't say that geom_function should be used instead. Where do you see that it has been superseded? Maybe I didn't look in the right place.

@ishaan-arora-1
Copy link
Contributor Author

overlay_function() was wrapping stat_function(), which has been superseded by geom_function() since ggplot2 3.3.0. Switched it over —

Hey @jgabry, to reframe the pr, instead of 'superseded' i should say 'recommended alternative' .
the ggplot2 3.3.2 states : 'A newly added geom_function() is now recommended to use in conjunction with/instead of stat_function()'

you should find it here exactly : https://ggplot2.tidyverse.org/news/index.html#ggplot2-332

Copy link
Member

@jgabry jgabry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the API is compatible since we just pass ... through

I don't think this is fully true. For example stat_function(..., geom = "point", inherit.aes = FALSE) produces a point layer whereas geom_function(..., geom = "point", inherit.aes = FALSE) warns that geom is unknown and keeps the default function geom. Since overlay_function() exposes ... this would technically be breaking backwards compatibility. I'm not sure if anyone is actually trying to specify geom, so maybe not a big deal, but I think since stat_function isn't actually deprecated we should avoid making this change.

We don't need to close this PR though, we can keep the size -> linewidth fix if you remove the stat_function change.

As requested: stat_function isn't deprecated, and switching to
geom_function could break backwards compatibility for users passing
geom via overlay_function(...). Only the size -> linewidth fix in
override.aes remains.
@ishaan-arora-1 ishaan-arora-1 changed the title Replace stat_function() with geom_function() and fix override.aes size (#449) Fix override.aes size to linewidth for linetype legend (#449) Mar 13, 2026
Copy link
Member

@jgabry jgabry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good thanks!

@jgabry jgabry merged commit bcf5ada into stan-dev:master Mar 13, 2026
6 checks passed
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.

3 participants