From fc7cc7ab4926b1f3dcf384828392e15a56801334 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Tue, 16 Jan 2024 11:41:50 +0100 Subject: [PATCH 1/3] deal with ggplot2 changes --- R/bayesplot-helpers.R | 6 +++++- tests/testthat/test-convenience-functions.R | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/R/bayesplot-helpers.R b/R/bayesplot-helpers.R index 0ae1f1e6..573835aa 100644 --- a/R/bayesplot-helpers.R +++ b/R/bayesplot-helpers.R @@ -333,7 +333,11 @@ calc_intervals <- function(x, p, med = TRUE, ...) { #' equivalent to using `legend_none()`. #' legend_move <- function(position = "right") { - theme(legend.position = position) + if (is.numeric(position) && "legend.position.inside" %in% fn_fmls_names(theme)) { + theme(legend.position = "inside", legend.position.inside = position) + } else { + theme(legend.position = position) + } } #' @rdname bayesplot-helpers #' @export diff --git a/tests/testthat/test-convenience-functions.R b/tests/testthat/test-convenience-functions.R index 693af99b..7389973e 100644 --- a/tests/testthat/test-convenience-functions.R +++ b/tests/testthat/test-convenience-functions.R @@ -110,7 +110,10 @@ test_that("legend_move returns correct theme object", { pos <- legend_move(c(0.25, 0.5)) expect_s3_class(pos, "theme") - expect_equivalent(pos, list(legend.position = c(0.25, 0.5))) + expect_equivalent( + pos$legend.position.inside %||% pos$legend.position, + c(0.25, 0.5) + ) expect_false(attr(pos, "complete")) }) test_that("legend_text returns correct theme object", { From ce32ee01e33b99904eac650ac5d409d17300fbb1 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Tue, 16 Jan 2024 12:04:43 +0100 Subject: [PATCH 2/3] replace `legend.text.align` --- R/bayesplot-ggplot-themes.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/R/bayesplot-ggplot-themes.R b/R/bayesplot-ggplot-themes.R index cf8b914d..f552b5fc 100644 --- a/R/bayesplot-ggplot-themes.R +++ b/R/bayesplot-ggplot-themes.R @@ -54,8 +54,7 @@ theme_default <- panel.spacing = unit(1.5, "lines"), legend.position = "right", legend.background = element_blank(), - legend.text = element_text(size = 13), - legend.text.align = 0, + legend.text = element_text(size = 13, hjust = 0), legend.key = element_blank() ) } From 7a42e2b4ddcd47a2c2925922aff04e3bd21bac20 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Tue, 16 Jan 2024 12:06:14 +0100 Subject: [PATCH 3/3] replace deprecated `facets` argument in `facet_grid()` --- R/mcmc-diagnostics.R | 2 +- R/mcmc-distributions.R | 2 +- R/mcmc-traces.R | 1 + R/ppc-errors.R | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/R/mcmc-diagnostics.R b/R/mcmc-diagnostics.R index 2751872a..8446540c 100644 --- a/R/mcmc-diagnostics.R +++ b/R/mcmc-diagnostics.R @@ -519,7 +519,7 @@ drop_NAs_and_warn <- function(x) { plot_data <- acf_data(x = x, lags = lags) if (num_chains(x) > 1) { - facet_args$facets <- "Chain ~ Parameter" + facet_args$rows <- "Chain ~ Parameter" facet_fun <- "facet_grid" } else { # 1 chain facet_args$facets <- "Parameter" diff --git a/R/mcmc-distributions.R b/R/mcmc-distributions.R index c975273a..b182cee3 100644 --- a/R/mcmc-distributions.R +++ b/R/mcmc-distributions.R @@ -409,7 +409,7 @@ mcmc_violin <- function( graph <- graph + do.call("facet_wrap", facet_args) } } else { - facet_args[["facets"]] <- if (n_param > 1) { + facet_args[["rows"]] <- if (n_param > 1) { "Chain ~ Parameter" } else { "Chain ~ ." diff --git a/R/mcmc-traces.R b/R/mcmc-traces.R index ed92060d..b0a08d0c 100644 --- a/R/mcmc-traces.R +++ b/R/mcmc-traces.R @@ -393,6 +393,7 @@ mcmc_rank_hist <- function(x, # Otherwise, use a grid. if (n_param > 1) { facet_f <- facet_grid + names(facet_args)[names(facet_args) == "facets"] <- "rows" } else { facet_f <- facet_wrap facet_args[["nrow"]] <- facet_args[["nrow"]] %||% 1 diff --git a/R/ppc-errors.R b/R/ppc-errors.R index 100a9cb1..baf9d617 100644 --- a/R/ppc-errors.R +++ b/R/ppc-errors.R @@ -398,7 +398,7 @@ error_hist_facets <- if (grouped) { facet_fun <- "facet_grid" - facet_args[["facets"]] <- rep_id ~ group + facet_args[["rows"]] <- rep_id ~ group } else { facet_fun <- "facet_wrap" facet_args[["facets"]] <- ~ rep_id