Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion R/plot_posterior.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#' `upper` and will contain the overflow. Use this arg to specify either a
#' single value to be used for all params, or a named numeric vector whose
#' names are params.
#' @param nrow,ncol Number of rows and columns for how the individual plots for
#' each parameter are arranged into a grid. Passed to [ggplot2::facet_wrap()].
#' @param skip_stanfit_to_dt If this argument is set to `TRUE`, the
#' `posterior_samples` argument (and the `prior_samples` argument if used)
#' should be used to provide a datatable of samples instead of a stanfit
Expand All @@ -65,6 +67,8 @@ plot_posterior <- function(posterior_samples,
labels = NA,
lower = NA,
upper = NA,
nrow = NA,
ncol = NA,
skip_stanfit_to_dt = NA,
bins = 30) {

Expand All @@ -79,6 +83,11 @@ plot_posterior <- function(posterior_samples,

check_numeric(bins, lower = 1)

# Recode defaults for nrow and ncol (NA, chosen so that they appear in the
# docs here) to NULL (their defaults in facet_wrap)
if (identical(NA, nrow)) nrow <- NULL
if (identical(NA, ncol)) ncol <- NULL

# Get the posterior samples into a dt with only the desired params
if (identical(skip_stanfit_to_dt, NA)) {
skip_stanfit_to_dt <- FALSE
Expand Down Expand Up @@ -334,7 +343,10 @@ plot_posterior <- function(posterior_samples,
}

plot <- ggplot2::ggplot(dt) +
ggplot2::facet_wrap(~ param, scales = "free") +
ggplot2::facet_wrap(~ param,
scales = "free",
nrow = nrow,
ncol = ncol) +
ggplot2::theme_classic() +
ggplot2::coord_cartesian(expand = FALSE)
if (have_prior) {
Expand Down
5 changes: 5 additions & 0 deletions man/plot_posterior.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/testthat/test-plot_posterior.R
Original file line number Diff line number Diff line change
Expand Up @@ -288,5 +288,6 @@ if (do_manual_visual_testing) {
plot_posterior(posterior_dt, prior_samples = prior_dt, upper = 10, skip_stanfit_to_dt = TRUE)
plot_posterior(posterior_dt, prior_samples = prior_dt, lower = 2, skip_stanfit_to_dt = TRUE)
plot_posterior(posterior_dt, prior_samples = prior_dt, lower = 2, upper = 10, skip_stanfit_to_dt = TRUE)
plot_posterior(posterior, nrow = 2)

}
Loading