grantmcdermott / tinyplot

Lightweight extension of the base R graphics system
https://grantmcdermott.com/tinyplot
Apache License 2.0
226 stars 7 forks source link

Support ribbon plots #46

Closed grantmcdermott closed 1 year ago

grantmcdermott commented 1 year ago

Closes #25

(Also fixes some lingering issues with the "pointrange" and "errorbar" types w.r.t. numeric intervals.)

grantmcdermott commented 1 year ago

@vincentarelbundock This might interest you. marginaleffects example:

library(marginaleffects)
dat = palmerpenguins::penguins

mod = lm(bill_length_mm ~ flipper_length_mm * species, data = dat)
pre = predictions(
    mod,
    newdata = datagrid(
        flipper_length_mm = fivenum,
        species = unique
    )
)

library(plot2)
par(las = 1)

 with(
     pre,
     plot2(
         x = flipper_length_mm, y = estimate,
         ymin = conf.low, ymax = conf.high,
         by = species,
         type = "ribbon",
         palette = "harmonic",
         frame = FALSE, grid = TRUE
     )
 )

Created on 2023-07-25 with reprex v2.0.2

(One nagging issue is that the default legend doesn't allow you to easily combine filled rectangles with lines. So right now we just keep the lines when a legend is printed. See Roman's solution here in case we decide to shipped our own, slightly modified legend2 function.)

vincentarelbundock commented 1 year ago

Oooh, this is suuuper neat!