Skip to content

Conversation

@grantmcdermott
Copy link
Owner

@grantmcdermott grantmcdermott commented Nov 21, 2025

Fixes #516

This ended up being trickier than I first thought b/c of different edge cases, but I think it's working well now. The core idea is pretty simple, though: We capture the x/ylab variables of an original plot layer and store them in our internal (tinyplot) environment. Then we match those up against any added layers that follow.

Examples

  1. Errorbar (original layer) + ribbon (secondary layer)
pkgload::load_all("~/Documents/Projects/tinyplot")
#> ℹ Loading tinyplot
library(broom)

coefs = tidy(lm(mpg ~ wt + drat, mtcars), conf.int = TRUE)

plt(
  estimate ~ term,
  ymin = conf.low, ymax = conf.high,
  data = coefs,
  type = "errorbar",
  theme = "basic"
)
plt_add(type = 'ribbon')

  1. Reverse case: Ribbon (original layer) + errorbar (secondary layer)
plt(
  estimate ~ term,
  ymin = conf.low, ymax = conf.high,
  data = coefs,
  type = "ribbon",
  theme = "basic"
)
plt_add(type = 'errorbar')

  1. Flipped example: Error bar (original layer) + line (secondary layer)
plt(
  estimate ~ term,
  ymin = conf.low, ymax = conf.high,
  data = coefs,
  type = "errorbar",
  theme = "basic",
  flip = TRUE
)
plt_add(type = 'l')

Created on 2025-11-20 with reprex v2.1.1

@grantmcdermott grantmcdermott merged commit d45368e into main Nov 21, 2025
3 checks passed
@grantmcdermott grantmcdermott deleted the add_xlabs_order branch November 21, 2025 05:52
This was referenced Nov 21, 2025
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.

Added layers should respect original x-axis order

2 participants