Option to make multivariate conditonal_effects panelplot?

I’m doing some work with multivariate models and want to make a panel plot / facetted plot where each plot is a different outcome. I could not find anything in the existing options.

So a reprex:

library(brms)
library(patchwork)

data("BTdata", package = "MCMCglmm")
head(BTdata)

fit3 <- brm(
    mvbind(tarsus, back) ~ sex + hatchdate,
    data = BTdata, chains = 2, cores = 2
)

plotdata <- conditional_effects(fit3, "hatchdate")
print(plotdata)
# This gives me two separate plots:

However I want both plot as panels/facets in a single plot. At the moment I’m doing this fairly manually as follows:

g1 <- ggplot(plotdata$tarsus.tarsus_hatchdate,
       aes(x=hatchdate, y=estimate__)) + geom_line() +
    geom_ribbon(aes(ymin = lower__, ymax = upper__, linetype=NA), alpha=0.15)
g2 <- ggplot(plotdata$back.back_hatchdate,
             aes(x=hatchdate, y=estimate__)) + geom_line() +
    geom_ribbon(aes(ymin = lower__, ymax = upper__, linetype=NA), alpha=0.15)
g1 + g2

Ok this is what I want but I’m having to redo formatting work etc etc.

Is there any built in option for conditional_effects, or some other easy way to achieve this that I have missed?

1 Like

Hi @jroon,

I’m afraid that what you do is actually what I always do :) I think that’s it.

Have you tried this:
Extract data from the plots, add a variable for the facet to each data.frame, rbind the to data.frames. now you can do the faceted plot with the new data.frame.

3 Likes

No not yet but I thought about it as alternative to the code above. I was hoping there was command or option to conditional_effects that I didnt’ find or something to do it in one line 😅

Yep. This or the patchwork solution from above is what I’d do. Also, if you ended up going the patchwork route for many panels, consider making a custom plotting function. You can find examples of how to do so here or here.

1 Like

Patchwork is amazing! 👍😅

1 Like