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
15 changes: 9 additions & 6 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@

* `mcmc_*()` functions now support all draws formats from the **posterior** package. (#277, @Ozan147)

* `mcmc_dens()` and `mcmc_dens_overlay()` gain arguments for controlling the
* `mcmc_dens()` and `mcmc_dens_overlay()` gain arguments for controlling the
the density calculation. (#258)

* `mcmc_hist()` and `mcmc_dens()` gain argument `alpha` for controlling transparency. (#244)

* `mcmc_areas()` and `mcmc_areas_ridges()` gain an argument `border_size` for
controlling the thickness of the ridgelines. (#224)

# bayesplot 1.8.1

* Fix R cmd check error on linux for CRAN
* Fix R cmd check error on linux for CRAN

# bayesplot 1.8.0

Expand All @@ -32,16 +35,16 @@
* New plotting function `ppc_km_overlay()` for outcome variables that are
right-censored. Empirical CCDF estimates of `yrep` are compared with the
Kaplan-Meier estimate of `y`. (#233, #234, @fweber144)

* `ppc_loo_pit_overlay()` now uses a boundary correction for an improved kernel
density estimation. The new argument `boundary_correction` defaults to TRUE but
can be set to FALSE to recover the old version of the plot. (#171, #235,
@ecoronado92)

* CmdStanMCMC objects (from CmdStanR) can now be used with extractor
functions `nuts_params()`, `log_posterior()`, `rhat()`, and
`neff_ratio()`. (#227)

* On the y axis, `ppc_loo_pit_qq(..., compare = "normal")` now plots standard
normal quantiles calculated from the PIT values (instead of the standardized
PIT values). (#240, #243, @fweber144)
Expand Down
31 changes: 26 additions & 5 deletions R/mcmc-intervals.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@
#' pars = c("alpha", "beta[4]"),
#' prob = 2/3,
#' prob_outer = 0.9,
#' point_est = "mean"
#' point_est = "mean",
#' border_size = 1.5 # make the ridgelines fatter
#' )
#' plot(p)
#'
Expand Down Expand Up @@ -176,7 +177,7 @@
#' # Example of hierarchically related parameters
#' # plotted with ridgelines
#' m <- shinystan::eight_schools@posterior_sample
#' mcmc_areas_ridges(m, pars = "mu", regex_pars = "theta") +
#' mcmc_areas_ridges(m, pars = "mu", regex_pars = "theta", border_size = 0.75) +
#' ggtitle("Treatment effect on eight schools (Rubin, 1981)")
#' }
#'
Expand Down Expand Up @@ -281,6 +282,8 @@ mcmc_intervals <- function(x,

#' @rdname MCMC-intervals
#' @export
#' @param border_size For `mcmc_areas()` and `mcmc_areas_ridges()`, the size of
#' the ridgelines.
mcmc_areas <- function(x,
pars = character(),
regex_pars = character(),
Expand All @@ -291,6 +294,7 @@ mcmc_areas <- function(x,
prob_outer = 1,
point_est = c("median", "mean", "none"),
rhat = numeric(),
border_size = NULL,
bw = NULL,
adjust = NULL,
kernel = NULL,
Expand Down Expand Up @@ -371,6 +375,12 @@ mcmc_areas <- function(x,
fill = NA
)

if (!is.null(border_size)) {
args_bottom$size <- border_size
args_outer$size <- border_size
args_inner$size <- border_size
}

if (color_by_rhat) {
args_bottom$mapping <- args_bottom$mapping %>%
modify_aes_(color = ~ rhat_rating)
Expand Down Expand Up @@ -432,8 +442,8 @@ mcmc_areas <- function(x,
scale_y_discrete(
limits = unique(rev(data$parameter)),
expand = expansion(
add = c(0, .5 + 1/(2 * nlevels(data$parameter))),
mult = c(.1, .1)
add = c(0, 0.5 + 1/(2 * nlevels(data$parameter))),
mult = c(0.05, 1/(2 * nlevels(data$parameter)))
)
) +
xlim(x_lim) +
Expand All @@ -454,6 +464,7 @@ mcmc_areas_ridges <- function(x,
...,
prob_outer = 1,
prob = 1,
border_size = NULL,
bw = NULL, adjust = NULL, kernel = NULL,
n_dens = NULL) {
check_ignored_arguments(...)
Expand Down Expand Up @@ -484,6 +495,9 @@ mcmc_areas_ridges <- function(x,
fill = NA,
stat = "identity"
)
if (!is.null(border_size)) {
args_outer$size <- border_size
}

layer_outer <- do.call(ggridges::geom_density_ridges, args_outer)

Expand Down Expand Up @@ -522,14 +536,21 @@ mcmc_areas_ridges <- function(x,
scale = scale,
stat = "identity")

if (!is.null(border_size)) {
args_inner$size <- border_size
}

layer_list_inner[[par_num]] <- do.call(ggridges::geom_ridgeline, args_inner)
}

ggplot(datas$outer) +
aes_(x = ~ x, y = ~ parameter) +
layer_outer +
scale_y_discrete(limits = unique(rev(data$parameter)),
expand = c(0.05, .6)) +
expand = expansion(
add = c(0, 1.4 + 1/(2 * nlevels(data$parameter))),
mult = c(0.05, 1/(2 * nlevels(data$parameter)))
)) +
layer_list_inner +
layer_vertical_line +
scale_fill_identity() +
Expand Down
10 changes: 8 additions & 2 deletions man/MCMC-intervals.Rd

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

105 changes: 50 additions & 55 deletions tests/figs/mcmc-intervals/mcmc-areas-ridges-default.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
105 changes: 50 additions & 55 deletions tests/figs/mcmc-intervals/mcmc-areas-ridges-inner.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
105 changes: 50 additions & 55 deletions tests/figs/mcmc-intervals/mcmc-areas-ridges-outer.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading