Skip to content

Commit c6919eb

Browse files
authored
Merge pull request #224 from stan-dev/ridgeline-size
allow changing size of ridgelines
2 parents 12b4188 + b006832 commit c6919eb

29 files changed

+2149
-178
lines changed

NEWS.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44

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

7-
* `mcmc_dens()` and `mcmc_dens_overlay()` gain arguments for controlling the
7+
* `mcmc_dens()` and `mcmc_dens_overlay()` gain arguments for controlling the
88
the density calculation. (#258)
9-
9+
1010
* `mcmc_hist()` and `mcmc_dens()` gain argument `alpha` for controlling transparency. (#244)
1111

12+
* `mcmc_areas()` and `mcmc_areas_ridges()` gain an argument `border_size` for
13+
controlling the thickness of the ridgelines. (#224)
14+
1215
# bayesplot 1.8.1
1316

14-
* Fix R cmd check error on linux for CRAN
17+
* Fix R cmd check error on linux for CRAN
1518

1619
# bayesplot 1.8.0
1720

@@ -32,16 +35,16 @@
3235
* New plotting function `ppc_km_overlay()` for outcome variables that are
3336
right-censored. Empirical CCDF estimates of `yrep` are compared with the
3437
Kaplan-Meier estimate of `y`. (#233, #234, @fweber144)
35-
38+
3639
* `ppc_loo_pit_overlay()` now uses a boundary correction for an improved kernel
3740
density estimation. The new argument `boundary_correction` defaults to TRUE but
3841
can be set to FALSE to recover the old version of the plot. (#171, #235,
3942
@ecoronado92)
40-
43+
4144
* CmdStanMCMC objects (from CmdStanR) can now be used with extractor
4245
functions `nuts_params()`, `log_posterior()`, `rhat()`, and
4346
`neff_ratio()`. (#227)
44-
47+
4548
* On the y axis, `ppc_loo_pit_qq(..., compare = "normal")` now plots standard
4649
normal quantiles calculated from the PIT values (instead of the standardized
4750
PIT values). (#240, #243, @fweber144)

R/mcmc-intervals.R

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@
7979
#' pars = c("alpha", "beta[4]"),
8080
#' prob = 2/3,
8181
#' prob_outer = 0.9,
82-
#' point_est = "mean"
82+
#' point_est = "mean",
83+
#' border_size = 1.5 # make the ridgelines fatter
8384
#' )
8485
#' plot(p)
8586
#'
@@ -176,7 +177,7 @@
176177
#' # Example of hierarchically related parameters
177178
#' # plotted with ridgelines
178179
#' m <- shinystan::eight_schools@posterior_sample
179-
#' mcmc_areas_ridges(m, pars = "mu", regex_pars = "theta") +
180+
#' mcmc_areas_ridges(m, pars = "mu", regex_pars = "theta", border_size = 0.75) +
180181
#' ggtitle("Treatment effect on eight schools (Rubin, 1981)")
181182
#' }
182183
#'
@@ -281,6 +282,8 @@ mcmc_intervals <- function(x,
281282

282283
#' @rdname MCMC-intervals
283284
#' @export
285+
#' @param border_size For `mcmc_areas()` and `mcmc_areas_ridges()`, the size of
286+
#' the ridgelines.
284287
mcmc_areas <- function(x,
285288
pars = character(),
286289
regex_pars = character(),
@@ -291,6 +294,7 @@ mcmc_areas <- function(x,
291294
prob_outer = 1,
292295
point_est = c("median", "mean", "none"),
293296
rhat = numeric(),
297+
border_size = NULL,
294298
bw = NULL,
295299
adjust = NULL,
296300
kernel = NULL,
@@ -371,6 +375,12 @@ mcmc_areas <- function(x,
371375
fill = NA
372376
)
373377

378+
if (!is.null(border_size)) {
379+
args_bottom$size <- border_size
380+
args_outer$size <- border_size
381+
args_inner$size <- border_size
382+
}
383+
374384
if (color_by_rhat) {
375385
args_bottom$mapping <- args_bottom$mapping %>%
376386
modify_aes_(color = ~ rhat_rating)
@@ -432,8 +442,8 @@ mcmc_areas <- function(x,
432442
scale_y_discrete(
433443
limits = unique(rev(data$parameter)),
434444
expand = expansion(
435-
add = c(0, .5 + 1/(2 * nlevels(data$parameter))),
436-
mult = c(.1, .1)
445+
add = c(0, 0.5 + 1/(2 * nlevels(data$parameter))),
446+
mult = c(0.05, 1/(2 * nlevels(data$parameter)))
437447
)
438448
) +
439449
xlim(x_lim) +
@@ -454,6 +464,7 @@ mcmc_areas_ridges <- function(x,
454464
...,
455465
prob_outer = 1,
456466
prob = 1,
467+
border_size = NULL,
457468
bw = NULL, adjust = NULL, kernel = NULL,
458469
n_dens = NULL) {
459470
check_ignored_arguments(...)
@@ -484,6 +495,9 @@ mcmc_areas_ridges <- function(x,
484495
fill = NA,
485496
stat = "identity"
486497
)
498+
if (!is.null(border_size)) {
499+
args_outer$size <- border_size
500+
}
487501

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

@@ -522,14 +536,21 @@ mcmc_areas_ridges <- function(x,
522536
scale = scale,
523537
stat = "identity")
524538

539+
if (!is.null(border_size)) {
540+
args_inner$size <- border_size
541+
}
542+
525543
layer_list_inner[[par_num]] <- do.call(ggridges::geom_ridgeline, args_inner)
526544
}
527545

528546
ggplot(datas$outer) +
529547
aes_(x = ~ x, y = ~ parameter) +
530548
layer_outer +
531549
scale_y_discrete(limits = unique(rev(data$parameter)),
532-
expand = c(0.05, .6)) +
550+
expand = expansion(
551+
add = c(0, 1.4 + 1/(2 * nlevels(data$parameter))),
552+
mult = c(0.05, 1/(2 * nlevels(data$parameter)))
553+
)) +
533554
layer_list_inner +
534555
layer_vertical_line +
535556
scale_fill_identity() +

man/MCMC-intervals.Rd

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/figs/mcmc-intervals/mcmc-areas-ridges-default.svg

Lines changed: 50 additions & 55 deletions
Loading

tests/figs/mcmc-intervals/mcmc-areas-ridges-inner.svg

Lines changed: 50 additions & 55 deletions
Loading

tests/figs/mcmc-intervals/mcmc-areas-ridges-outer.svg

Lines changed: 50 additions & 55 deletions
Loading

0 commit comments

Comments
 (0)