From bde88f82a1c3343f7172a38aa4f3e4cef34777f3 Mon Sep 17 00:00:00 2001 From: Teun van den Brand <49372158+teunbrand@users.noreply.github.com> Date: Mon, 7 Aug 2023 22:00:22 +0200 Subject: [PATCH] Convert `size` -> `linewidth` in `annotation_logticks()` (#5330) --- NEWS.md | 4 +++- R/annotation-logticks.R | 23 +++++++++++++++-------- man/annotation_logticks.Rd | 9 ++++++--- tests/testthat/_snaps/annotate.md | 5 +++++ tests/testthat/test-annotate.R | 4 ++++ 5 files changed, 33 insertions(+), 12 deletions(-) diff --git a/NEWS.md b/NEWS.md index 64d2529a02..8fe979a6a8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # ggplot2 (development version) +* The `size` argument in `annotation_logticks()` has been deprecated in favour + of the `linewidth` argument (#5292). + * `geom_boxplot()` gains an `outliers` argument to switch outliers on or off, in a manner that does affects the scale range. For hiding outliers that does not affect the scale range, you can continue to use `outlier.shape = NA` @@ -14,7 +17,6 @@ deprecated. The `hjust` setting of the `legend.text` and `legend.title` elements continues to fulfil the role of text alignment (@teunbrand, #5347). - * Integers are once again valid input to theme arguments that expect numeric input (@teunbrand, #5369) diff --git a/R/annotation-logticks.R b/R/annotation-logticks.R index 62cb58114d..3432cac3b5 100644 --- a/R/annotation-logticks.R +++ b/R/annotation-logticks.R @@ -21,11 +21,12 @@ #' using `scale_y_log10()`. It should be `FALSE` when using #' `coord_trans(y = "log10")`. #' @param colour Colour of the tick marks. -#' @param size Thickness of tick marks, in mm. +#' @param linewidth Thickness of tick marks, in mm. #' @param linetype Linetype of tick marks (`solid`, `dashed`, etc.) #' @param alpha The transparency of the tick marks. #' @param color An alias for `colour`. #' @param ... Other parameters passed on to the layer +#' @param size `r lifecycle::badge("deprecated")` #' #' @export #' @seealso [scale_y_continuous()], [scale_y_log10()] for log scale @@ -81,11 +82,17 @@ #' ) annotation_logticks <- function(base = 10, sides = "bl", outside = FALSE, scaled = TRUE, short = unit(0.1, "cm"), mid = unit(0.2, "cm"), long = unit(0.3, "cm"), - colour = "black", size = 0.5, linetype = 1, alpha = 1, color = NULL, ...) + colour = "black", linewidth = 0.5, linetype = 1, alpha = 1, color = NULL, ..., + size = deprecated()) { if (!is.null(color)) colour <- color + if (lifecycle::is_present(size)) { + deprecate_soft0("3.5.0", I("Using the `size` aesthetic in this geom"), I("`linewidth`")) + linewidth <- linewidth %||% size + } + layer( data = dummy_data(), mapping = NULL, @@ -103,7 +110,7 @@ annotation_logticks <- function(base = 10, sides = "bl", outside = FALSE, scaled mid = mid, long = long, colour = colour, - size = size, + linewidth = linewidth, linetype = linetype, alpha = alpha, ... @@ -163,14 +170,14 @@ GeomLogticks <- ggproto("GeomLogticks", Geom, ticks$x_b <- with(data, segmentsGrob( x0 = unit(xticks$x, "native"), x1 = unit(xticks$x, "native"), y0 = unit(xticks$start, "cm"), y1 = unit(xticks$end, "cm"), - gp = gpar(col = alpha(colour, alpha), lty = linetype, lwd = size * .pt) + gp = gpar(col = alpha(colour, alpha), lty = linetype, lwd = linewidth * .pt) )) } if (grepl("t", sides) && nrow(xticks) > 0) { ticks$x_t <- with(data, segmentsGrob( x0 = unit(xticks$x, "native"), x1 = unit(xticks$x, "native"), y0 = unit(1, "npc") - unit(xticks$start, "cm"), y1 = unit(1, "npc") - unit(xticks$end, "cm"), - gp = gpar(col = alpha(colour, alpha), lty = linetype, lwd = size * .pt) + gp = gpar(col = alpha(colour, alpha), lty = linetype, lwd = linewidth * .pt) )) } } @@ -201,14 +208,14 @@ GeomLogticks <- ggproto("GeomLogticks", Geom, ticks$y_l <- with(data, segmentsGrob( y0 = unit(yticks$y, "native"), y1 = unit(yticks$y, "native"), x0 = unit(yticks$start, "cm"), x1 = unit(yticks$end, "cm"), - gp = gpar(col = alpha(colour, alpha), lty = linetype, lwd = size * .pt) + gp = gpar(col = alpha(colour, alpha), lty = linetype, lwd = linewidth * .pt) )) } if (grepl("r", sides) && nrow(yticks) > 0) { ticks$y_r <- with(data, segmentsGrob( y0 = unit(yticks$y, "native"), y1 = unit(yticks$y, "native"), x0 = unit(1, "npc") - unit(yticks$start, "cm"), x1 = unit(1, "npc") - unit(yticks$end, "cm"), - gp = gpar(col = alpha(colour, alpha), lty = linetype, lwd = size * .pt) + gp = gpar(col = alpha(colour, alpha), lty = linetype, lwd = linewidth * .pt) )) } } @@ -216,7 +223,7 @@ GeomLogticks <- ggproto("GeomLogticks", Geom, gTree(children = inject(gList(!!!ticks))) }, - default_aes = aes(colour = "black", size = 0.5, linetype = 1, alpha = 1) + default_aes = aes(colour = "black", linewidth = 0.5, linetype = 1, alpha = 1) ) diff --git a/man/annotation_logticks.Rd b/man/annotation_logticks.Rd index 35083eb1e2..088daf1fe1 100644 --- a/man/annotation_logticks.Rd +++ b/man/annotation_logticks.Rd @@ -13,11 +13,12 @@ annotation_logticks( mid = unit(0.2, "cm"), long = unit(0.3, "cm"), colour = "black", - size = 0.5, + linewidth = 0.5, linetype = 1, alpha = 1, color = NULL, - ... + ..., + size = deprecated() ) } \arguments{ @@ -47,7 +48,7 @@ long tick marks. In base 10, these are the "1" (or "10") ticks.} \item{colour}{Colour of the tick marks.} -\item{size}{Thickness of tick marks, in mm.} +\item{linewidth}{Thickness of tick marks, in mm.} \item{linetype}{Linetype of tick marks (\code{solid}, \code{dashed}, etc.)} @@ -56,6 +57,8 @@ long tick marks. In base 10, these are the "1" (or "10") ticks.} \item{color}{An alias for \code{colour}.} \item{...}{Other parameters passed on to the layer} + +\item{size}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}}} } \description{ This annotation adds log tick marks with diminishing spacing. diff --git a/tests/testthat/_snaps/annotate.md b/tests/testthat/_snaps/annotate.md index 8bc64a7561..22f7005c0a 100644 --- a/tests/testthat/_snaps/annotate.md +++ b/tests/testthat/_snaps/annotate.md @@ -29,3 +29,8 @@ Unequal parameter lengths: x (3), y (3), and fill (2) +# annotation_logticks warns about deprecated `size` argument + + Using the `size` aesthetic in this geom was deprecated in ggplot2 3.5.0. + i Please use `linewidth` instead. + diff --git a/tests/testthat/test-annotate.R b/tests/testthat/test-annotate.R index 2407475059..68bfcd4e26 100644 --- a/tests/testthat/test-annotate.R +++ b/tests/testthat/test-annotate.R @@ -77,3 +77,7 @@ test_that("unsupported geoms signal a warning (#4719)", { test_that("annotate() checks aesthetic lengths match", { expect_snapshot_error(annotate("point", 1:3, 1:3, fill = c('red', 'black'))) }) + +test_that("annotation_logticks warns about deprecated `size` argument", { + expect_snapshot_warning(annotation_logticks(size = 5)) +})