Skip to content

Commit a2923d4

Browse files
committed
close #216
1 parent 39b55fa commit a2923d4

2 files changed

Lines changed: 28 additions & 19 deletions

File tree

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()

0 commit comments

Comments
 (0)