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
- 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')
- 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')
- 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