Skip to content

Commit 4ebc2ac

Browse files
authored
Merge pull request #217 from stan-dev/issue-216
Issue 216
2 parents 10284e5 + ff85ced commit 4ebc2ac

9 files changed

Lines changed: 738 additions & 28 deletions

File tree

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Depends:
2626
R (>= 3.1.0)
2727
Imports:
2828
dplyr (>= 0.8.0),
29-
ggplot2 (>= 2.2.1),
29+
ggplot2 (>= 3.0.0),
3030
ggridges,
3131
glue,
3232
reshape2,
@@ -49,7 +49,7 @@ Suggests:
4949
shinystan (>= 2.3.0),
5050
testthat (>= 2.0.0),
5151
vdiffr
52-
RoxygenNote: 7.0.1
52+
RoxygenNote: 7.0.2
5353
VignetteBuilder: knitr
5454
Encoding: UTF-8
5555
Roxygen: list(markdown = TRUE)

R/helpers-gg.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ space_legend_keys <- function(relative_size = 2, color = "white") {
9797

9898
# set aesthetic mapping for histograms depending on freq argument
9999
set_hist_aes <- function(freq = TRUE, ...) {
100-
if (freq)
100+
if (freq) {
101101
aes_(x = ~ value, ...)
102-
else
103-
aes_(x = ~ value, y = ~ ..density.., ...)
102+
} else {
103+
aes_(x = ~ value, y = ~ stat(density), ...)
104+
}
104105
}

R/mcmc-distributions.R

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -301,26 +301,30 @@ mcmc_violin <- function(x,
301301

302302

303303

304+
304305
# internal -----------------------------------------------------------------
305306
.mcmc_hist <- function(x,
306-
pars = character(),
307-
regex_pars = character(),
308-
transformations = list(),
309-
facet_args = list(),
310-
binwidth = NULL,
311-
breaks = NULL,
312-
by_chain = FALSE,
313-
freq = TRUE,
314-
...) {
307+
pars = character(),
308+
regex_pars = character(),
309+
transformations = list(),
310+
facet_args = list(),
311+
binwidth = NULL,
312+
breaks = NULL,
313+
by_chain = FALSE,
314+
freq = TRUE,
315+
...) {
315316
x <- prepare_mcmc_array(x, pars, regex_pars, transformations)
316-
if (by_chain && !has_multiple_chains(x))
317+
318+
if (by_chain && !has_multiple_chains(x)) {
317319
STOP_need_multiple_chains()
320+
}
318321

319322
data <- melt_mcmc(x, value.name = "value")
320323
n_param <- num_params(data)
321324

322-
graph <- ggplot(data, set_hist_aes(freq)) +
325+
graph <- ggplot(data, aes(x = ~ value)) +
323326
geom_histogram(
327+
set_hist_aes(freq),
324328
fill = get_color("mid"),
325329
color = get_color("mid_highlight"),
326330
size = .25,
@@ -336,15 +340,19 @@ mcmc_violin <- function(x,
336340
graph <- graph + do.call("facet_wrap", facet_args)
337341
}
338342
} else {
339-
facet_args[["facets"]] <- if (n_param > 1)
340-
"Chain ~ Parameter" else "Chain ~ ."
343+
facet_args[["facets"]] <- if (n_param > 1) {
344+
"Chain ~ Parameter"
345+
} else {
346+
"Chain ~ ."
347+
}
341348
graph <- graph +
342349
do.call("facet_grid", facet_args) +
343350
force_axes_in_facets()
344351
}
345352

346-
if (n_param == 1)
353+
if (n_param == 1) {
347354
graph <- graph + xlab(levels(data$Parameter))
355+
}
348356

349357
graph +
350358
dont_expand_y_axis(c(0.005, 0)) +
@@ -405,8 +413,8 @@ mcmc_violin <- function(x,
405413
geom_args[["color"]] <- get_color("mid_highlight")
406414
}
407415

408-
graph <- ggplot(data, mapping = do.call("aes_", aes_mapping)) +
409-
do.call(geom_fun, geom_args)
416+
graph <- ggplot(data, mapping = do.call("aes_", aes_mapping)) +
417+
do.call(geom_fun, geom_args)
410418

411419
if (!violin) {
412420
graph <- graph + dont_expand_x_axis()

R/mcmc-intervals.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
#' color_scheme_set("brightblue")
6161
#' mcmc_intervals(x)
6262
#' mcmc_intervals(x, pars = c("beta[1]", "beta[2]"))
63-
#' mcmc_areas(x, regex_pars = "beta\\\[[1-3]\\\]", prob = 0.8) +
63+
#' mcmc_areas(x, regex_pars = "beta\\[[1-3]\\]", prob = 0.8) +
6464
#' ggplot2::labs(
6565
#' title = "Posterior distributions",
6666
#' subtitle = "with medians and 80% intervals"

R/mcmc-scatterplots.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,17 +220,17 @@ mcmc_hex <- function(x,
220220
#'
221221
#' # pairs plots
222222
#' # default of condition=NULL implies splitting chains between upper and lower panels
223-
#' mcmc_pairs(x, pars = "alpha", regex_pars = "beta\\\[[1,4]\\\]",
223+
#' mcmc_pairs(x, pars = "alpha", regex_pars = "beta\\[[1,4]\\]",
224224
#' off_diag_args = list(size = 1, alpha = 0.5))
225225
#'
226226
#' # change to density plots instead of histograms and hex plots instead of
227227
#' # scatterplots
228-
#' mcmc_pairs(x, pars = "alpha", regex_pars = "beta\\\[[1,4]\\\]",
228+
#' mcmc_pairs(x, pars = "alpha", regex_pars = "beta\\[[1,4]\\]",
229229
#' diag_fun = "dens", off_diag_fun = "hex")
230230
#'
231231
#' # plot chain 1 above diagonal and chains 2, 3, and 4 below
232232
#' color_scheme_set("brightblue")
233-
#' mcmc_pairs(x, pars = "alpha", regex_pars = "beta\\\[[1,4]\\\]",
233+
#' mcmc_pairs(x, pars = "alpha", regex_pars = "beta\\[[1,4]\\]",
234234
#' diag_fun = "dens", off_diag_fun = "hex",
235235
#' condition = pairs_condition(chains = list(1, 2:4)))
236236
#' }

man/MCMC-scatterplots.Rd

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

0 commit comments

Comments
 (0)