Skip to content

Commit 654d22c

Browse files
authored
Merge branch 'master' into ppc-rootogram-grouped
2 parents f433a60 + a30a706 commit 654d22c

25 files changed

Lines changed: 112 additions & 76 deletions

.github/workflows/test-coverage.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
1919

2020
steps:
21-
- uses: actions/checkout@v4
21+
- uses: actions/checkout@v6
2222

2323
- uses: r-lib/actions/setup-r@v2
2424
with:

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Description: Plotting functions for posterior analysis, MCMC diagnostics,
2626
License: GPL (>= 3)
2727
URL: https://mc-stan.org/bayesplot/
2828
BugReports: https://github.com/stan-dev/bayesplot/issues/
29-
SystemRequirements: pandoc (>= 1.12.3), pandoc-citeproc
29+
SystemRequirements: pandoc (>= 1.12.3)
3030
Depends:
3131
R (>= 4.1.0)
3232
Imports:

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# bayesplot (development version)
22

3+
* Use `rlang::warn()` and `rlang::inform()` for selected PPC user messages instead of base `warning()` and `message()`.
4+
* Standardize input validation errors in `ppc_km_overlay()` and interpolation helpers to use `rlang::abort()` for consistent error handling.
35
* Fix assignment-in-call bug in `mcmc_rank_ecdf()` (#).
46
* Replaced deprecated `dplyr` and `tidyselect` functions (`top_n`, `one_of`, `group_indices`) with their modern equivalents to ensure future compatibility. (#431)
57
* Documentation added for all exported `*_data()` functions (#209)
@@ -8,6 +10,9 @@
810
* Fixed test in `test-ppc-distributions.R` that incorrectly used `ppc_dens()` instead of `ppd_dens()` when testing PPD functions
911
* New functions `mcmc_dots` and `mcmc_dots_by_chain` for dot plots of MCMC draws by @behramulukir (#402)
1012
* Default to `quantiles=100` for all dot plots by @behramulukir (#402)
13+
* Use `"neff_ratio"` consistently in diagnostic color scale helpers to avoid relying on partial matching of `"neff"`.
14+
* Replace `expand = c(mult, add)` with `ggplot2::expansion()` helper in scale functions for consistency with ggplot2 >= 3.3.0 style.
15+
* Replace uses of `geom_bar(stat = "identity")` with the more idiomatic ggplot2 form `geom_col()`
1116

1217
# bayesplot 1.15.0
1318

R/bayesplot-colors.R

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ color_scheme_view <- function(scheme = NULL) {
189189

190190
#' @export
191191
print.bayesplot_scheme <- function(x, ...) {
192-
tab <- data.frame(unlist(x, use.names = FALSE), stringsAsFactors = FALSE)
192+
tab <- data.frame(unlist(x, use.names = FALSE))
193193
colnames(tab) <- attr(x, "scheme_name") %||% "hex_color"
194194
print(tab, ...)
195195
}
@@ -222,9 +222,8 @@ plot_scheme <- function(scheme = NULL) {
222222
)
223223

224224
ggplot(color_data, aes(x = .data$name, y = .data$value, fill = .data$group)) +
225-
geom_bar(
225+
geom_col(
226226
width = .5,
227-
stat = "identity",
228227
color = "white",
229228
linewidth = 0.1
230229
) +

R/helpers-gg.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ modify_aes <- function(mapping, ...) {
3737
facet_wrap_parsed <- function(...) {
3838
facet_wrap(..., labeller = label_parsed)
3939
}
40-
dont_expand_y_axis <- function(expand = c(0,0)) {
40+
dont_expand_y_axis <- function(expand = expansion(0, 0)) {
4141
scale_y_continuous(expand = expand)
4242
}
43-
dont_expand_x_axis <- function(expand = c(0,0)) {
43+
dont_expand_x_axis <- function(expand = expansion(0, 0)) {
4444
scale_x_continuous(expand = expand)
4545
}
4646
dont_expand_axes <- function() {

R/helpers-ppc.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ interpolate_gamma <- function(N, K, prob, L) {
456456
get_interpolation_values <- function(N, K, L, prob) {
457457
for (dim in c("L", "prob")) {
458458
if (all(get(dim) != .gamma_adj[, dim])) {
459-
stop(paste(
459+
abort(paste(
460460
"No precomputed values to interpolate from for '", dim, "' = ",
461461
get(dim),
462462
".\n",
@@ -469,7 +469,7 @@ get_interpolation_values <- function(N, K, L, prob) {
469469
}
470470
vals <- .gamma_adj[.gamma_adj$L == L & .gamma_adj$prob == prob, ]
471471
if (N > max(vals$N)) {
472-
stop(paste(
472+
abort(paste(
473473
"No precomputed values to interpolate from for sample length of ",
474474
N,
475475
".\n",
@@ -480,7 +480,7 @@ get_interpolation_values <- function(N, K, L, prob) {
480480
))
481481
}
482482
if (N < min(vals$N)) {
483-
stop(paste(
483+
abort(paste(
484484
"No precomputed values to interpolate from for sample length of ",
485485
N,
486486
".\n",
@@ -491,7 +491,7 @@ get_interpolation_values <- function(N, K, L, prob) {
491491
))
492492
}
493493
if (K > max(vals[vals$N <= N, ]$K)) {
494-
stop(paste(
494+
abort(paste(
495495
"No precomputed values available for interpolation for 'K' = ",
496496
K,
497497
".\n",
@@ -502,7 +502,7 @@ get_interpolation_values <- function(N, K, L, prob) {
502502
))
503503
}
504504
if (K < min(vals[vals$N <= N, ]$K)) {
505-
stop(paste(
505+
abort(paste(
506506
"No precomputed values available for interpolation for 'K' = ",
507507
K,
508508
".\n",

R/mcmc-diagnostics-nuts.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ mcmc_nuts_acceptance <-
183183
)
184184
}
185185
hists <- hists +
186-
dont_expand_y_axis(c(0.005, 0)) +
186+
dont_expand_y_axis(expansion(mult = 0.005, add = 0)) +
187187
facet_wrap(vars(.data$Parameter), scales = "free") +
188188
yaxis_text(FALSE) +
189189
yaxis_title(FALSE) +
@@ -483,8 +483,8 @@ mcmc_nuts_energy <-
483483
) +
484484
scale_fill_manual("", values = fills, labels = aes_labs) +
485485
scale_color_manual("", values = clrs, labels = aes_labs) +
486-
dont_expand_y_axis(c(0.005, 0)) +
487-
scale_x_continuous(expand = c(0.2, 0)) +
486+
dont_expand_y_axis(expansion(mult = 0.005, add = 0)) +
487+
scale_x_continuous(expand = expansion(mult = 0.2, add = 0)) +
488488
labs(y = NULL, x = expression(E - bar(E))) +
489489
bayesplot_theme_get() +
490490
space_legend_keys() +

R/mcmc-diagnostics.R

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ mcmc_rhat <- function(rhat, ..., size = NULL) {
170170
labs(y = NULL, x = expression(hat(R))) +
171171
scale_fill_diagnostic("rhat") +
172172
scale_color_diagnostic("rhat") +
173-
scale_x_continuous(breaks = brks, expand = c(0, .01)) +
174-
scale_y_discrete(expand = c(.025,0)) +
173+
scale_x_continuous(breaks = brks, expand = expansion(mult = 0, add = 0.01)) +
174+
scale_y_discrete(expand = expansion(mult = 0.025, add = 0)) +
175175
yaxis_title(FALSE) +
176176
yaxis_text(FALSE) +
177177
yaxis_ticks(FALSE)
@@ -199,7 +199,7 @@ mcmc_rhat_hist <- function(rhat, ..., binwidth = NULL, bins = NULL, breaks = NUL
199199
scale_color_diagnostic("rhat") +
200200
scale_fill_diagnostic("rhat") +
201201
labs(x = expression(hat(R)), y = NULL) +
202-
dont_expand_y_axis(c(0.005, 0)) +
202+
dont_expand_y_axis(expansion(mult = 0.005, add = 0)) +
203203
bayesplot_theme_get() +
204204
yaxis_title(FALSE) +
205205
yaxis_text(FALSE) +
@@ -255,14 +255,14 @@ mcmc_neff <- function(ratio, ..., size = NULL) {
255255
linetype = 2,
256256
linewidth = 0.25) +
257257
labs(y = NULL, x = expression(N[eff]/N)) +
258-
scale_fill_diagnostic("neff") +
259-
scale_color_diagnostic("neff") +
258+
scale_fill_diagnostic("neff_ratio") +
259+
scale_color_diagnostic("neff_ratio") +
260260
scale_x_continuous(
261261
breaks = breaks,
262262
# as.character truncates trailing zeroes, while ggplot default does not
263263
labels = as.character(breaks),
264264
limits = c(0, max(1, max_ratio) + 0.05),
265-
expand = c(0, 0)) +
265+
expand = expansion(0, 0)) +
266266
bayesplot_theme_get() +
267267
yaxis_text(FALSE) +
268268
yaxis_title(FALSE) +
@@ -287,10 +287,10 @@ mcmc_neff_hist <- function(ratio, ..., binwidth = NULL, bins = NULL, breaks = NU
287287
binwidth = binwidth,
288288
bins = bins,
289289
breaks = breaks) +
290-
scale_color_diagnostic("neff") +
291-
scale_fill_diagnostic("neff") +
290+
scale_color_diagnostic("neff_ratio") +
291+
scale_fill_diagnostic("neff_ratio") +
292292
labs(x = expression(N[eff]/N), y = NULL) +
293-
dont_expand_y_axis(c(0.005, 0)) +
293+
dont_expand_y_axis(expansion(mult = 0.005, add = 0)) +
294294
yaxis_title(FALSE) +
295295
yaxis_text(FALSE) +
296296
yaxis_ticks(FALSE) +
@@ -424,12 +424,12 @@ diagnostic_points <- function(size = NULL) {
424424

425425
# Functions wrapping around scale_color_manual() and scale_fill_manual(), used to
426426
# color the intervals by rhat value
427-
scale_color_diagnostic <- function(diagnostic = c("rhat", "neff")) {
427+
scale_color_diagnostic <- function(diagnostic = c("rhat", "neff_ratio")) {
428428
d <- match.arg(diagnostic)
429429
diagnostic_color_scale(d, aesthetic = "color")
430430
}
431431

432-
scale_fill_diagnostic <- function(diagnostic = c("rhat", "neff")) {
432+
scale_fill_diagnostic <- function(diagnostic = c("rhat", "neff_ratio")) {
433433
d <- match.arg(diagnostic)
434434
diagnostic_color_scale(d, aesthetic = "fill")
435435
}
@@ -541,9 +541,7 @@ drop_NAs_and_warn <- function(x) {
541541
bayesplot_theme_get()
542542
if (style == "bar") {
543543
graph <- graph +
544-
geom_bar(
545-
position = "identity",
546-
stat = "identity",
544+
geom_col(
547545
linewidth = 0.2,
548546
fill = get_color("l"),
549547
color = get_color("lh"),
@@ -574,7 +572,7 @@ drop_NAs_and_warn <- function(x) {
574572
scale_x_continuous(
575573
limits = c(-0.5, lags + 0.5),
576574
breaks = function(x) as.integer(pretty(x, n = 3)),
577-
expand = c(0, 0)
575+
expand = expansion(0, 0)
578576
) +
579577
labs(x = "Lag", y = "Autocorrelation") +
580578
force_axes_in_facets()

R/mcmc-distributions.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ mcmc_dens_chains <- function(
332332
labs(color = "Chain") +
333333
scale_y_discrete(
334334
limits = unique(rev(data$parameter)),
335-
expand = c(0.05, .6)
335+
expand = expansion(mult = 0.05, add = 0.6)
336336
) +
337337
scale_color +
338338
bayesplot_theme_get() +
@@ -523,7 +523,7 @@ mcmc_dots_by_chain <- function(
523523
}
524524

525525
graph +
526-
dont_expand_y_axis(c(0.005, 0)) +
526+
dont_expand_y_axis(expansion(mult = 0.005, add = 0)) +
527527
bayesplot_theme_get() +
528528
yaxis_text(FALSE) +
529529
yaxis_title(FALSE) +
@@ -642,7 +642,7 @@ mcmc_dots_by_chain <- function(
642642
}
643643

644644
graph +
645-
dont_expand_y_axis(c(0.005, 0)) +
645+
dont_expand_y_axis(expansion(mult = 0.005, add = 0)) +
646646
bayesplot_theme_get() +
647647
yaxis_text(FALSE) +
648648
yaxis_ticks(FALSE) +
@@ -703,7 +703,7 @@ mcmc_dots_by_chain <- function(
703703
}
704704

705705
graph +
706-
dont_expand_y_axis(c(0.005, 0)) +
706+
dont_expand_y_axis(expansion(mult = 0.005, add = 0)) +
707707
bayesplot_theme_get() +
708708
yaxis_text(FALSE) +
709709
yaxis_title(FALSE) +

R/mcmc-parcoord.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ mcmc_parcoord <-
132132

133133

134134
divg <- sym("Divergent")
135-
draws <- dplyr::filter(data, UQ(divg) == 0)
136-
div_draws <- dplyr::filter(data, UQ(divg) == 1)
135+
draws <- dplyr::filter(data, !!divg == 0)
136+
div_draws <- dplyr::filter(data, !!divg == 1)
137137
has_divs <- isTRUE(nrow(div_draws) > 0)
138138

139139
graph <- ggplot(draws, aes(
@@ -159,7 +159,7 @@ mcmc_parcoord <-
159159
}
160160

161161
graph +
162-
scale_x_discrete(expand = c(0,0), labels = levels(draws$Parameter)) +
162+
scale_x_discrete(expand = expansion(0, 0), labels = levels(draws$Parameter)) +
163163
expand_limits(x = nlevels(draws$Parameter) + 0.25) +
164164
labs(x = NULL, y = NULL)
165165
}
@@ -191,7 +191,7 @@ mcmc_parcoord_data <-
191191
# 'Parameter' and 'Value' so need to be a little careful)
192192
divs <- np %>%
193193
validate_nuts_data_frame() %>%
194-
dplyr::filter(UQ(param) == "divergent__") %>%
194+
dplyr::filter(!!param == "divergent__") %>%
195195
select(- !!param) %>%
196196
rename("Divergent" = !!value)
197197

0 commit comments

Comments
 (0)