grantmcdermott · GitHub

@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.)

Read the original on github.com ↗