Skip to content

Fix ignored position argument in violin jitter layer - #106

Merged
maxkarlsson merged 1 commit into
mainfrom
cursor/fix-violin-jitter-position-warning-36d4
Sep 8, 2026
Merged

maxkarlsson merged 1 commit into
mainfrom
cursor/fix-violin-jitter-position-warning-36d4

Conversation

@maxkarlsson

@maxkarlsson maxkarlsson commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Problem

Rendering a report emitted two warnings per plot pair from component_abundance_per_marker():

Warning in p <- p + :
  Ignoring unknown parameters: `position`

The warning came from the jitter layer in plot_violin():

geom_quasirandom(
  ...,
  position = position_quasirandom(width = "units", dodge.width = 0.9)
)

ggbeeswarm::geom_quasirandom() does not take a position argument. It constructs its own position_quasirandom() object from its named arguments (method, width, varwidth, bandwidth, nbins, dodge.width, orientation) and forwards everything else to the layer's params. The position object therefore ended up as an unknown geom parameter: ggplot2 warned about it and dropped it, so the intended dodge.width = 0.9 never had any effect. The width = "units" value was also invalid (width is numeric, the maximum amount of spread) and would have errored if the position object had actually been used.

Fix

Pass dodge.width = 0.9 directly to geom_quasirandom() and let it build the position. width is left at its default, which is derived from the resolution of the (already dodged) x positions, so the point spread adapts to the violin widths instead of being hard-coded.

The now-unused ggbeeswarm::position_quasirandom import was removed.

Verification

Reproduced the warning and confirmed the fix with ggplot2 4.0.3 and ggbeeswarm 0.7.3, running the pre-fix and post-fix plot_violin() bodies side by side against sample data.

For the plots the report actually draws today, where each sample_alias maps to a single condition, the points are unchanged and only the warning disappears:

Abundance violin plot before and after the fix

When a fill variable has several levels per x category, the dropped dodge.width was also visible: the points were spread across the whole category instead of following their own violin, leaving many of them outside any violin. They are now dodged along with the violins.

Violin plot with two fill levels per x category, before and after the fix

The built layer data agrees with the images: in the two-level case the point clouds spanned 0.62–1.37 for both node types before the fix, and now sit at 0.604–0.942 and 1.066–1.388, matching their violin extents of 0.55–1.00 and 1.00–1.45.

The existing plot_violin test now asserts that no warning is raised and that the jitter layer is dodged by 0.9.

To show artifacts inline, enable in settings.

Open in Web Open in Cursor 

Co-authored-by: max.karlsson <max.karlsson@pixelgen.com>
@maxkarlsson
maxkarlsson marked this pull request as ready for review September 8, 2026 12:44
@maxkarlsson
maxkarlsson requested a lite review from Copilot September 8, 2026 14:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The core fix and associated test/import/changelog updates are coherent and low-risk, addressing the warning and restoring intended dodge behavior.

Pull request overview

This PR fixes an incorrect use of position with ggbeeswarm::geom_quasirandom() in plot_violin(), eliminating a ggplot2 warning and ensuring jittered points are properly dodged with violins.

Changes:

  • Update plot_violin() to pass dodge.width = 0.9 directly to geom_quasirandom() (instead of supplying a position object that gets ignored).
  • Remove the unused position_quasirandom import from package roxygen and NAMESPACE.
  • Strengthen the existing plot_violin test to assert no warning is emitted and that the jitter layer uses PositionQuasirandom with dodge.width = 0.9.
File summaries
File Description
tests/testthat/test_plot_helpers.R Updates plot_violin test to assert no warning and verify jitter dodging via the layer position object.
R/plot_helpers.R Fixes quasi-random jitter configuration by passing dodge.width directly to geom_quasirandom().
R/pixelatorES-package.R Removes the now-unused position_quasirandom import from roxygen imports.
NAMESPACE Drops position_quasirandom import to match updated usage.
CHANGELOG.md Documents the warning removal and correct dodging behavior for violin plot points.
Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread R/plot_helpers.R
Comment on lines +791 to +794
# geom_quasirandom() builds its own position object from these
# arguments; a position_quasirandom() object passed as `position` is
# silently dropped
dodge.width = 0.9
@maxkarlsson
maxkarlsson merged commit 52688a2 into main Sep 8, 2026
8 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