R Packages for Plotting 'brms' models


This is not an analytical question. I am simply curious which packages people prefer or suggest is “best” for making publication quality plots for models developed using the ‘brms’ R package. So far I’ve identified the following packages and did not know if there were others or if anyone had a really strong opinion on using one over the others.

  1. tidybayes
  2. marginaleffects
  3. brmsmargins

I’ll be plotting multilevel, multivariate distributional models with different outcome distributions (though I’ll likely plot them on the response scale). I already use tidybayes for model diagnostics and fit (who doesn’t?) and have used marginaleffects for previous projects, I’m just curious others’ opinions on making final publication-ready plots. Thanks!

There’s also the bayesplot and posterior packages, which may be helpful for extracting output and visualising your model fits.

Personally, when it comes to publication-ready figures for a specific project, I tend to use tidybayes in combination with tidyverse tools like dplyr and tidyr to wrangle the output in the desired format, and then use standard ggplot2 functions (perhaps with ggdist) to plot. In some cases I might be reinventing the wheel, but at least this way I feel like I have full control over the plots.


Yeah, it’s looking like I’m going to use a combination of ‘posterior’ and then ‘tidybayes’ at this point. I’m going to work with the ‘marginaleffects’ package author to see if we can get support for distributional models. That package is just so much more elegant in implementation.

I agree with you that ‘stacking’ from multiple packages gives you the most flexibility, particularly for final reports. I’ve also realized how lazy I’ve gotten in my old age. (insert grouchy old man voice) “In my day, you didn’t have any of these fancy packages like ‘emmeans’, you had to write your own code! The only thing ‘tidy’ was our rooms if we decided to make the bed that morning!”


This is a fine list. The only thing you’re missing is patchwork, which can come in handy when you need to combine multiple plots, and maybe paletteer for choosing a good color scheme.


I’d add, if you’re doing multilevel / multivariate models, you might give posterior::rvar() a try. It’s designed so that you can pass the output from brms::posterior_epred(), brms::posterior_linpred(), and brms::posterior_predict() directly to it, and then you can add the resulting rvars to a data frame and visualize output using ggdist (which can take rvars on the xdist and ydist aesthetics). If you’re manipulating multidimensional posterior variables they are also helpful in that they preserve dimensions and act essentially like base R arrays. They are intended to make it feel, as much as possible, like you are still using a probabilistic programming language from within R.