Warn when position_jitterdodge() groups are inflated beyond fill#6825
Draft
Jesssullivan wants to merge 2 commits intotidyverse:mainfrom
Draft
Warn when position_jitterdodge() groups are inflated beyond fill#6825Jesssullivan wants to merge 2 commits intotidyverse:mainfrom
Jesssullivan wants to merge 2 commits intotidyverse:mainfrom
Conversation
When additional discrete aesthetics (e.g., colour) are mapped in a point layer using position_jitterdodge(), the implicit group becomes finer than the fill-based dodging of boxplots, causing misalignment. This adds a targeted warning in setup_params() that detects when dodge groups exceed fill levels, guiding users to set aes(group = <fill variable>). Also adds a @section to the documentation explaining the grouping interaction, with examples showing the pitfall and fix.
This was referenced Mar 29, 2026
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.
Warn when
position_jitterdodge()groups are inflated beyond fillRelates to #6824.
Depending on thoughts about this 👀 I also am opening a sister PR that instead modifies default behavior, which may or may not be preferable.
position_jitterdodge()silently misaligns points when additional discrete aesthetics (e.g.,colour) are mapped in the point layer. The implicit group becomes finer than thefill-based dodge of the boxplot, but no diagnostic is emitted. The workaround (aes(group = <fill variable>)) requires understanding the implicit grouping mechanism, which is non-obvious.Warning (
R/position-jitterdodge.R): Insetup_params(), whenfillis present and discrete, compare the number of unique groups per x-position against the number of unique fill values. When groups exceed fills, emit acli::cli_warn()with the fix. Uses the samevec_unique/vec_group_id/tabulatepattern already at lines 63-65 of the function.Does not fire when: the user has already set
group = <fill_var>, onlyfillis mapped,fillis absent, orfillis continuous.Documentation (
R/position-jitterdodge.R): New@section Interaction with grouping:explains the mechanism and theaes(group = ...)fix. New\donttest{}example demonstrates the pitfall and solution using a small data frame.Tests (
tests/testthat/test-position-jitterdodge.R): 4 new tests covering warning/no-warning scenarios; these may be overkill.NEWS (
NEWS.md): Entry added.Checklist
@Jesssullivan, #6824)cli::cli_warn()patterns in position codedevtools::document()run