Infer dodge grouping from fill in position_jitterdodge()#6826
Open
Jesssullivan wants to merge 2 commits intotidyverse:mainfrom
Open
Infer dodge grouping from fill in position_jitterdodge()#6826Jesssullivan wants to merge 2 commits intotidyverse:mainfrom
Jesssullivan wants to merge 2 commits intotidyverse:mainfrom
Conversation
position_jitterdodge() now derives dodge grouping from the fill aesthetic when present and discrete, rather than from the full implicit group interaction. This ensures points align correctly with dodged boxplots even when additional discrete aesthetics like colour are mapped in the point layer. When fill is absent or continuous, behaviour falls back to the standard group aesthetic, preserving backward compatibility.
Author
|
FWIW, I prefer this inference solution to retroactive documentation route Draft PR - 6825, keen to hear others thoughts @krosepulham 👀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Infer dodge grouping from
fillinposition_jitterdodge()Closes #6824.
Motivation
position_jitterdodge()is documented as "primarily used for aligning points generated throughgeom_point()with dodged boxplots (e.g., ageom_boxplot()with a fill aesthetic supplied)." However, the function currently derives dodge grouping from the full implicitgroupinteraction, which includes every discrete aesthetic in the layer — not justfill. Addingcolour,shape, orlinetypesilently breaks the alignment this function is designed to provide.Approach
Since this function exists specifically for boxplot+point alignment, and boxplots dodge by
fill, the dodge grouping should derive fromfillwhen available.A 6-line unexported helper (
jitterdodge_dodge_group) checks whetherfillis present and discrete, returning either a fill-based group or falling back to the standardgroup. Three methods (setup_params,setup_data,compute_panel) use this helper to temporarily swap the group for dodging, then restore the original group for downstream use. No new parameters are added.Note on existing behaviour
We understand that ggplot2 is a mature package and that PRs changing existing behaviour require careful consideration. This change only affects the case where the current output is visually incorrect:
fillonlyfill+colourfillfillThe only behaviour change is in the case where the current result contradicts the function's documented purpose. Users who need the old grouping can use
aes(group = interaction(fill, colour))explicitly.Changes
R/position-jitterdodge.R:jitterdodge_dodge_group()helper + modifications tosetup_params,setup_data,compute_panelR/position-jitterdodge.R: New@section Dodge grouping:documenting the inference and fallbacktests/testthat/test-position-jitterdodge.R: 5 new tests (alignment, backward compat, no-fill fallback, continuous-fill fallback, existing preserve tests still pass)NEWS.md: Entry addedChecklist
@Jesssullivan, #6824)id(),is_discrete()devtools::document()run@examples