Skip to content

Commit

Permalink
Merge pull request #309 from teunbrand/master
Browse files Browse the repository at this point in the history
Update for new ggplot2 release
  • Loading branch information
jgabry authored Jan 17, 2024
2 parents ac1005d + 7a42e2b commit b1ef699
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 7 deletions.
3 changes: 1 addition & 2 deletions R/bayesplot-ggplot-themes.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
}
Expand Down
6 changes: 5 additions & 1 deletion R/bayesplot-helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion R/mcmc-diagnostics.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion R/mcmc-distributions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 ~ ."
Expand Down
1 change: 1 addition & 0 deletions R/mcmc-traces.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion R/ppc-errors.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion tests/testthat/test-convenience-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down

0 comments on commit b1ef699

Please sign in to comment.