diff --git a/DESCRIPTION b/DESCRIPTION index 9f47b08b..6b28a199 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -34,6 +34,7 @@ Imports: ggplot2 (>= 3.4.0), ggridges (>= 0.5.5), glue, + lifecycle, posterior, reshape2, rlang (>= 0.3.0), diff --git a/NAMESPACE b/NAMESPACE index b8cf818b..56bfb045 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -226,3 +226,6 @@ importFrom(dplyr,top_n) importFrom(dplyr,ungroup) importFrom(dplyr,vars) importFrom(ggplot2,"%+replace%") +importFrom(lifecycle,deprecate_warn) +importFrom(lifecycle,deprecated) +importFrom(lifecycle,is_present) diff --git a/R/bayesplot-helpers.R b/R/bayesplot-helpers.R index d3d86ec3..f5467946 100644 --- a/R/bayesplot-helpers.R +++ b/R/bayesplot-helpers.R @@ -446,19 +446,28 @@ plot_bg <- function(on = TRUE, ...) { #' @rdname bayesplot-helpers #' @export -#' @param color,size Passed to [ggplot2::element_line()]. -#' -grid_lines <- function(color = "gray50", size = 0.2) { +#' @param color,linewidth Passed to [ggplot2::element_line()]. +#' @param size `r lifecycle::badge("deprecated")` Use `linewidth` instead. +#' +grid_lines <- function(color = "gray50", linewidth = 0.2, size = deprecated()) { + if (lifecycle::is_present(size)) { + lifecycle::deprecate_warn( + "1.16.0", + "grid_lines(size)", + "grid_lines(linewidth)" + ) + linewidth <- size + } theme( - panel.grid.major = element_line(color = color, linewidth = size), - panel.grid.minor = element_line(color = color, linewidth = size * 0.5) + panel.grid.major = element_line(color = color, linewidth = linewidth), + panel.grid.minor = element_line(color = color, linewidth = linewidth * 0.5) ) } -grid_lines_y <- function(color = "gray50", size = 0.2) { +grid_lines_y <- function(color = "gray50", linewidth = 0.2) { theme( - panel.grid.major.y = element_line(color = color, linewidth = size), - panel.grid.minor.y = element_line(color = color, linewidth = size * 0.5) + panel.grid.major.y = element_line(color = color, linewidth = linewidth), + panel.grid.minor.y = element_line(color = color, linewidth = linewidth * 0.5) ) } diff --git a/R/bayesplot-package.R b/R/bayesplot-package.R index 2727a62a..db740a9a 100644 --- a/R/bayesplot-package.R +++ b/R/bayesplot-package.R @@ -5,6 +5,7 @@ #' #' @import ggplot2 stats rlang #' @importFrom dplyr %>% summarise group_by select +#' @importFrom lifecycle deprecated deprecate_warn is_present #' #' @description #' \if{html}{ diff --git a/R/helpers-gg.R b/R/helpers-gg.R index 953a51d4..21ec794a 100644 --- a/R/helpers-gg.R +++ b/R/helpers-gg.R @@ -24,17 +24,10 @@ geom_ignore <- function(...) { #' Add new aesthetic mappings to a list of aesthetic mappings #' -#' @param mapping a list of `uneval` aesthetic mappings (created by `aes_()`) -#' @param ... additional mappings to add, e.g., `color = ~ parameter` +#' @param mapping a list of `uneval` aesthetic mappings (created by `aes()`) +#' @param ... additional mappings to add using `.data$` syntax #' @return the updated list #' @noRd -modify_aes_ <- function(mapping, ...) { - utils::modifyList(mapping, aes_(...)) -} - -#' Same as `modify_aes_` but using `aes()` instead of `aes_()` (now deprecated). -#' Often `...` will need to contain expression of the form `.data$x` to avoid R cmd check warnings -#' @noRd modify_aes <- function(mapping, ...) { utils::modifyList(mapping, aes(...)) } diff --git a/R/mcmc-diagnostics.R b/R/mcmc-diagnostics.R index 2727928f..f363026d 100644 --- a/R/mcmc-diagnostics.R +++ b/R/mcmc-diagnostics.R @@ -77,7 +77,7 @@ #' (p <- mcmc_acf_bar(x, pars = c("alpha", "beta[1]"))) #' #' # add horiztonal dashed line at 0.5 -#' p + hline_at(0.5, linetype = 2, size = 0.15, color = "gray") +#' p + hline_at(0.5, linetype = 2, linewidth = 0.15, color = "gray") #' } #' #' # fake rhat values to use for demonstration diff --git a/R/mcmc-scatterplots.R b/R/mcmc-scatterplots.R index 4d32391c..d4f939e1 100644 --- a/R/mcmc-scatterplots.R +++ b/R/mcmc-scatterplots.R @@ -109,7 +109,7 @@ #' color_scheme_set("pink") #' (p3 <- mcmc_scatter(x, pars = c("alpha", "beta[3]"), alpha = 0.25, size = 3)) #' p3 + geom_smooth(method = "lm", se = FALSE, color = "gray20", -#' size = .75, linetype = 2) +#' linewidth = .75, linetype = 2) #' #' \donttest{ #' if (requireNamespace("hexbin", quietly = TRUE)) { diff --git a/man/MCMC-diagnostics.Rd b/man/MCMC-diagnostics.Rd index 35e589dc..f6dbad81 100644 --- a/man/MCMC-diagnostics.Rd +++ b/man/MCMC-diagnostics.Rd @@ -163,7 +163,7 @@ color_scheme_set("pink") (p <- mcmc_acf_bar(x, pars = c("alpha", "beta[1]"))) # add horiztonal dashed line at 0.5 -p + hline_at(0.5, linetype = 2, size = 0.15, color = "gray") +p + hline_at(0.5, linetype = 2, linewidth = 0.15, color = "gray") } # fake rhat values to use for demonstration diff --git a/man/MCMC-scatterplots.Rd b/man/MCMC-scatterplots.Rd index e82f0797..8799e2a0 100644 --- a/man/MCMC-scatterplots.Rd +++ b/man/MCMC-scatterplots.Rd @@ -313,7 +313,7 @@ p2 + stat_density_2d(color = "black", size = .5) color_scheme_set("pink") (p3 <- mcmc_scatter(x, pars = c("alpha", "beta[3]"), alpha = 0.25, size = 3)) p3 + geom_smooth(method = "lm", se = FALSE, color = "gray20", - size = .75, linetype = 2) + linewidth = .75, linetype = 2) \donttest{ if (requireNamespace("hexbin", quietly = TRUE)) { diff --git a/man/bayesplot-helpers.Rd b/man/bayesplot-helpers.Rd index 897bce92..460511d0 100644 --- a/man/bayesplot-helpers.Rd +++ b/man/bayesplot-helpers.Rd @@ -63,7 +63,7 @@ panel_bg(on = TRUE, ...) plot_bg(on = TRUE, ...) -grid_lines(color = "gray50", size = 0.2) +grid_lines(color = "gray50", linewidth = 0.2, size = deprecated()) overlay_function(...) } @@ -112,7 +112,9 @@ example, facet text can be removed by adding \code{facet_text(on=FALSE)}, or simply \code{facet_text(FALSE)} to a ggplot object. If \code{on=TRUE} (the default), then \code{...} can be used to customize the appearance of the theme element.} -\item{color, size}{Passed to \code{\link[ggplot2:element]{ggplot2::element_line()}}.} +\item{color, linewidth}{Passed to \code{\link[ggplot2:element]{ggplot2::element_line()}}.} + +\item{size}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Use \code{linewidth} instead.} } \value{ A \strong{ggplot2} layer or \code{\link[ggplot2:theme]{ggplot2::theme()}} object that can be diff --git a/tests/testthat/test-convenience-functions.R b/tests/testthat/test-convenience-functions.R index 7b197f27..a6f76499 100644 --- a/tests/testthat/test-convenience-functions.R +++ b/tests/testthat/test-convenience-functions.R @@ -63,7 +63,7 @@ test_that("lbub works", { # plot and facet backgrounds ---------------------------------------------- test_that("grid_lines returns correct theme object", { - thm <- theme_default() + grid_lines(size = 1.5, color = "purple") + thm <- theme_default() + grid_lines(linewidth = 1.5, color = "purple") expect_equal(thm$panel.grid.major, element_line(linewidth = 1.5, color = "purple")) expect_equal(thm$panel.grid.minor, element_line(linewidth = 0.75, color = "purple")) })