Skip to content

Commit 0c24254

Browse files
authored
Merge pull request #221 from hhau/master
add facet_args to mcmc_rank_overlay
2 parents 13c10df + dfb9b87 commit 0c24254

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

R/mcmc-traces.R

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ mcmc_rank_overlay <- function(x,
266266
pars = character(),
267267
regex_pars = character(),
268268
transformations = list(),
269+
facet_args = list(),
269270
...,
270271
n_bins = 20,
271272
ref_line = FALSE) {
@@ -278,6 +279,7 @@ mcmc_rank_overlay <- function(x,
278279
)
279280

280281
n_chains <- unique(data$n_chains)
282+
n_param <- unique(data$n_parameters)
281283

282284
# We have to bin and count the data ourselves because
283285
# ggplot2::stat_bin(geom = "step") does not draw the final bin.
@@ -314,12 +316,19 @@ mcmc_rank_overlay <- function(x,
314316
} else {
315317
NULL
316318
}
317-
319+
320+
facet_call <- NULL
321+
if (n_param > 1) {
322+
facet_args$facets <- ~ parameter
323+
facet_args$scales <- facet_args$scales %||% "fixed"
324+
facet_call <- do.call("facet_wrap", facet_args)
325+
}
326+
318327
ggplot(d_bin_counts) +
319328
aes_(x = ~ bin_start, y = ~ n, color = ~ chain) +
320329
geom_step() +
321330
layer_ref_line +
322-
facet_wrap("parameter") +
331+
facet_call +
323332
scale_color +
324333
ylim(c(0, NA)) +
325334
bayesplot_theme_get() +

0 commit comments

Comments
 (0)