Skip to content

Commit e36f040

Browse files
authored
Merge pull request #244 from stan-dev/mcmc-hist-dens-alpha
Add alpha argument to mcmc_hist and mcmc_dens
2 parents c95dba7 + df8cc4e commit e36f040

File tree

7 files changed

+801
-9
lines changed

7 files changed

+801
-9
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
density estimation. The new argument `boundary_correction` defaults to TRUE but
3434
can be set to FALSE to recover the old version of the plot. (#171, #235,
3535
@ecoronado92)
36+
37+
* `mcmc_hist()` and `mcmc_dens()` gain argument `alpha` for controling transparency. (#244)
3638

3739
* CmdStanMCMC objects (from CmdStanR) can now be used with extractor
3840
functions `nuts_params()`, `log_posterior()`, `rhat()`, and

R/mcmc-distributions.R

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#' @template args-facet_args
1414
#' @template args-density-controls
1515
#' @param ... Currently ignored.
16+
#' @param alpha Passed to the geom to control the transparency.
1617
#'
1718
#' @template return-ggplot
1819
#'
@@ -115,7 +116,8 @@ mcmc_hist <- function(
115116
facet_args = list(),
116117
binwidth = NULL,
117118
breaks = NULL,
118-
freq = TRUE
119+
freq = TRUE,
120+
alpha = 1
119121
) {
120122
check_ignored_arguments(...)
121123
.mcmc_hist(
@@ -128,6 +130,7 @@ mcmc_hist <- function(
128130
breaks = breaks,
129131
by_chain = FALSE,
130132
freq = freq,
133+
alpha = alpha,
131134
...
132135
)
133136
}
@@ -145,7 +148,8 @@ mcmc_dens <- function(
145148
bw = NULL,
146149
adjust = NULL,
147150
kernel = NULL,
148-
n_dens = NULL
151+
n_dens = NULL,
152+
alpha = 1
149153
) {
150154
check_ignored_arguments(...)
151155
.mcmc_dens(
@@ -160,6 +164,7 @@ mcmc_dens <- function(
160164
adjust = adjust,
161165
kernel = kernel,
162166
n_dens = n_dens,
167+
alpha = alpha,
163168
...
164169
)
165170
}
@@ -175,7 +180,8 @@ mcmc_hist_by_chain <- function(
175180
...,
176181
facet_args = list(),
177182
binwidth = NULL,
178-
freq = TRUE
183+
freq = TRUE,
184+
alpha = 1
179185
) {
180186
check_ignored_arguments(...)
181187
.mcmc_hist(
@@ -187,6 +193,7 @@ mcmc_hist_by_chain <- function(
187193
binwidth = binwidth,
188194
by_chain = TRUE,
189195
freq = freq,
196+
alpha = alpha,
190197
...
191198
)
192199
}
@@ -363,6 +370,7 @@ mcmc_violin <- function(
363370
breaks = NULL,
364371
by_chain = FALSE,
365372
freq = TRUE,
373+
alpha = 1,
366374
...
367375
) {
368376
x <- prepare_mcmc_array(x, pars, regex_pars, transformations)
@@ -382,7 +390,8 @@ mcmc_violin <- function(
382390
size = .25,
383391
na.rm = TRUE,
384392
binwidth = binwidth,
385-
breaks = breaks
393+
breaks = breaks,
394+
alpha = alpha
386395
)
387396

388397
facet_args[["scales"]] <- facet_args[["scales"]] %||% "free"
@@ -426,6 +435,7 @@ mcmc_violin <- function(
426435
geom = c("density", "violin"),
427436
probs = c(0.1, 0.5, 0.9),
428437
trim = FALSE,
438+
alpha = 1,
429439
bw = NULL,
430440
adjust = NULL,
431441
kernel = NULL,
@@ -460,8 +470,7 @@ mcmc_violin <- function(
460470
} else {
461471
list(x = ~ Value)
462472
}
463-
464-
geom_args <- list(size = 0.5, na.rm = TRUE)
473+
geom_args <- list(size = 0.5, na.rm = TRUE, alpha = alpha)
465474
if (violin) {
466475
geom_args[["draw_quantiles"]] <- probs
467476
} else {
@@ -519,4 +528,3 @@ mcmc_violin <- function(
519528
yaxis_title(on = n_param == 1 && violin) +
520529
xaxis_title(on = n_param == 1)
521530
}
522-

man/MCMC-distributions.Rd

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

tests/figs/mcmc-distributions/mcmc-dens-alpha.svg

Lines changed: 209 additions & 0 deletions
Loading

tests/figs/mcmc-distributions/mcmc-dens-default.svg

Lines changed: 209 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)