Skip to content

Commit

Permalink
control sizes of intervals and points in mcmc_intervals (#229)
Browse files Browse the repository at this point in the history
* Add arguments to change interval and point size

Fixes #228
Fixes #215

* add visual test

* Update NEWS.md

Co-authored-by: TJ Mahr <tjmahr@users.noreply.github.com>
  • Loading branch information
jgabry and tjmahr committed Jul 2, 2020
1 parent 1485ebd commit 794f220
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 3 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions R/mcmc-intervals.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(...)

Expand All @@ -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
)

Expand Down
8 changes: 8 additions & 0 deletions man/MCMC-intervals.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 64 additions & 0 deletions tests/figs/mcmc-intervals/mcmc-intervals-sizes.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions tests/testthat/test-mcmc-intervals.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down

0 comments on commit 794f220

Please sign in to comment.