bayesplot is an R package providing an extensive library of plotting functions for use after fitting Bayesian models (typically with MCMC). Currently bayesplot offers a variety of plots of posterior draws, visual MCMC diagnostics, as well as graphical posterior predictive checking. Additional functionality (e.g. for forecasting/out-of-sample prediction and other inference-related tasks) will be added in future releases.
The plots created by bayesplot are ggplot objects, which means that after a plot is created it can be further customized using the various functions for modifying ggplot objects provided by the ggplot2 package.
The idea behind bayesplot is not only to provide convenient functionality for users, but also a common set of functions that can be easily used by developers working on a variety of packages for Bayesian modeling, particularly (but not necessarily) those powered by RStan.
Install the latest release from CRAN:
Install the latest development version from GitHub:
You can also set
build_vignettes=FALSE for a faster installation from GitHub (the vignettes can always be accessed online anytime at mc-stan.org/bayesplot/articles). For issues related to pandoc see the Readme
# with rstan demo model library("rstan") fit2 <- stan_demo("eight_schools", warmup = 300, iter = 700) posterior2 <- extract(fit2, inc_warmup = TRUE, permuted = FALSE) color_scheme_set("mix-blue-pink") p <- mcmc_trace(posterior2, pars = c("mu", "tau"), n_warmup = 300, facet_args = list(nrow = 2, labeller = label_parsed)) p + facet_text(size = 15)
# another example with rstanarm color_scheme_set("purple") fit <- stan_glmer(mpg ~ wt + (1|cyl), data = mtcars) ppc_intervals( y = mtcars$mpg, yrep = posterior_predict(fit), x = mtcars$wt, prob = 0.5 ) + labs( x = "Weight (1000 lbs)", y = "MPG", title = "50% posterior predictive intervals \nvs observed miles per gallon", subtitle = "by vehicle weight" ) + panel_bg(fill = "gray95", color = NA) + grid_lines(color = "white")