Skip to content

Jittered layering + offsets#561

Merged
grantmcdermott merged 4 commits intomainfrom
layer_offset
Mar 23, 2026
Merged

Jittered layering + offsets#561
grantmcdermott merged 4 commits intomainfrom
layer_offset

Conversation

@grantmcdermott
Copy link
Copy Markdown
Owner

Fixes #493

Jitter layers added via tinyplot_add() now align correctly with grouped boxplot, violin, and ridge base layers.

Operationalized through the new group_offset setting, which the different data_* constructor functions can access. This also means that offsets are calculated ahead of time, instead of during the drawing phase (which is probably more robust anyway).

MWEs:

pkgload::load_all('~/Documents/Projects/tinyplot')
#> ℹ Loading tinyplot

plt(
  body_mass ~ sex | species, data = penguins,
  flip = TRUE,
  type = "box",
  theme = "clean"
)
plt_add(type = "j", cex = 0.5)

plt(
  body_mass ~ sex | species, data = penguins,
  flip = TRUE,
  type = "violin",
  bg = 0.2,
  theme = "clean"
)
plt_add(type = "j", cex = 0.5)

The "ridge" layering still doesn't look great b/c the colours don't inherit from the base layer and points near the baseline may be clipped by ylim... But those are separate issues IMO.

plt(
  sex ~ body_mass, data = penguins,
  type = "ridge",
  theme = "ridge"
)
plt_add(type = "j", cex = 0.5)

Created on 2026-03-23 with reprex v2.1.1

- ridge support still doesn't look great b/c (a) bottom jitter is being cut off, and (b) color mismatch... but those are separate issues.
@grantmcdermott grantmcdermott merged commit 7550b27 into main Mar 23, 2026
3 checks passed
@grantmcdermott grantmcdermott deleted the layer_offset branch March 23, 2026 20:42
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.

Misalignment when layering on top of plots with adjusted axis breaks

1 participant