Fix mcmc_areas_ridges() overlay breaking with + scale_y_discrete()#432
Fix mcmc_areas_ridges() overlay breaking with + scale_y_discrete()#432utkarshpawade wants to merge 2 commits intostan-dev:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where mcmc_areas_ridges() would break when users appended + scale_y_discrete() to the returned plot. Previously, the draw order was enforced via limits = inside an internal scale_y_discrete() call; ggplot2 silently replaced this when a user supplied their own scale, discarding the limits = and flipping the ridgeline draw order.
Changes:
- Draw order is now encoded directly in the factor levels of
data$parameter(reversed), removing the need forlimits =inscale_y_discrete() par_draw_orderupdated torev(levels(...))to match the new factor encoding- Unit tests and a
vdiffrsnapshot added for the regression case
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
R/mcmc-intervals.R |
Core fix: reverses factor levels on data$parameter and drops limits = from scale_y_discrete() |
tests/testthat/test-mcmc-intervals.R |
Adds unit test and vdiffr snapshot for the previously broken scale_y_discrete overlay case |
NEWS.md |
Documents the bug fix in the changelog |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #432 +/- ##
==========================================
- Coverage 98.66% 98.63% -0.04%
==========================================
Files 35 35
Lines 5860 5862 +2
==========================================
Hits 5782 5782
- Misses 78 80 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thanks for the PR! I'm not sure this is working correctly. This does fix the overlay issue when using |
Fixes #287
mcmc_areas_ridges()usedscale_y_discrete(limits = ...)internally to set the y-axis draw order. When users added their own+ scale_y_discrete(...)(eg to rename labels), ggplot2 replaced the entire scale (including the limits) which flipped the draw order and broke ridgeline masking.This fix encodes the draw order directly in the factor levels of
data$parameter(reversed so the first parameter appears on top), instead of relying onlimits =. User-addedscale_y_discrete()calls can now change labels without affecting the overlay order.Changes:
mcmc-intervals.R: reverse factor levels before building layers,remove
limits =fromscale_y_discrete(), updatepar_draw_ordertest-mcmc-intervals.R: add unit tests andvdiffrsnapshot for thepreviously failing case