diff --git a/NEWS.md b/NEWS.md index 4bf6d25a..3d7a5b5c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -9,6 +9,8 @@ --> * Added missing `facet_args` argument to `mcmc_rank_overlay()`. (#221, @hhau) +* Size of points and interval lines can set in + `mcmc_intervals(..., outer_size, inner_size, point_size)`. (#215, #228, #229) # bayesplot 1.7.2 diff --git a/R/mcmc-intervals.R b/R/mcmc-intervals.R index f70aaa83..abb9b2fb 100644 --- a/R/mcmc-intervals.R +++ b/R/mcmc-intervals.R @@ -25,6 +25,9 @@ #' `"equal height"` are scaled using `height*sqrt(height)` #' @param point_est The point estimate to show. Either `"median"` (the #' default), `"mean"`, or `"none"`. +#' @param inner_size,outer_size For `mcmc_intervals()`, the size of +#' the inner and interval segments, respectively. +#' @param point_size For `mcmc_intervals()`, the size of point estimate. #' @param rhat An optional numeric vector of R-hat estimates, with one element #' per parameter included in `x`. If `rhat` is provided, the intervals/areas #' and point estimates in the resulting plot are colored based on R-hat value. @@ -160,6 +163,9 @@ mcmc_intervals <- function(x, prob = 0.5, prob_outer = 0.9, point_est = c("median", "mean", "none"), + outer_size = 0.5, + inner_size = 2, + point_size = 4, rhat = numeric()) { check_ignored_arguments(...) @@ -184,17 +190,18 @@ mcmc_intervals <- function(x, args_outer <- list( mapping = aes_(x = ~ ll, xend = ~ hh, y = ~ parameter, yend = ~ parameter), - color = get_color("mid") + color = get_color("mid"), + size = outer_size ) args_inner <- list( mapping = aes_(x = ~ l, xend = ~ h, y = ~ parameter, yend = ~ parameter), - size = 2, + size = inner_size, show.legend = FALSE ) args_point <- list( mapping = aes_(x = ~ m, y = ~ parameter), data = data, - size = 4, + size = point_size, shape = 21 ) diff --git a/man/MCMC-intervals.Rd b/man/MCMC-intervals.Rd index 0c057c97..89ed3020 100644 --- a/man/MCMC-intervals.Rd +++ b/man/MCMC-intervals.Rd @@ -19,6 +19,9 @@ mcmc_intervals( prob = 0.5, prob_outer = 0.9, point_est = c("median", "mean", "none"), + outer_size = 0.5, + inner_size = 2, + point_size = 4, rhat = numeric() ) @@ -151,6 +154,11 @@ default is \code{0.9} for \code{mcmc_intervals()} (90\% interval) and \item{point_est}{The point estimate to show. Either \code{"median"} (the default), \code{"mean"}, or \code{"none"}.} +\item{inner_size, outer_size}{For \code{mcmc_intervals()}, the size of +the inner and interval segments, respectively.} + +\item{point_size}{For \code{mcmc_intervals()}, the size of point estimate.} + \item{rhat}{An optional numeric vector of R-hat estimates, with one element per parameter included in \code{x}. If \code{rhat} is provided, the intervals/areas and point estimates in the resulting plot are colored based on R-hat value. diff --git a/tests/figs/mcmc-intervals/mcmc-intervals-sizes.svg b/tests/figs/mcmc-intervals/mcmc-intervals-sizes.svg new file mode 100644 index 00000000..a6372308 --- /dev/null +++ b/tests/figs/mcmc-intervals/mcmc-intervals-sizes.svg @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +V5 +V4 +V3 +V2 +V1 + + + + + + + + + + + +-2 +-1 +0 +1 +2 +mcmc_intervals (sizes) + diff --git a/tests/testthat/test-mcmc-intervals.R b/tests/testthat/test-mcmc-intervals.R index aa1e4364..0159da19 100644 --- a/tests/testthat/test-mcmc-intervals.R +++ b/tests/testthat/test-mcmc-intervals.R @@ -197,6 +197,9 @@ test_that("mcmc_intervals renders correctly", { p_mean_points <- mcmc_intervals(vdiff_dframe, point_est = "mean") vdiffr::expect_doppelganger("mcmc_intervals (means)", p_mean_points) + + p_sizes <- mcmc_intervals(vdiff_dframe, point_size = 1, inner_size = 5, outer_size = 4) + vdiffr::expect_doppelganger("mcmc_intervals (sizes)", p_sizes) }) test_that("mcmc_areas renders correctly", {