Skip to content

Commit

Permalink
Convert size -> linewidth in annotation_logticks() (#5330)
Browse files Browse the repository at this point in the history
  • Loading branch information
teunbrand committed Aug 7, 2023
1 parent da2a8e8 commit bde88f8
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -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`
Expand All @@ -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)

Expand Down
23 changes: 15 additions & 8 deletions R/annotation-logticks.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
...
Expand Down Expand Up @@ -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)
))
}
}
Expand Down Expand Up @@ -201,22 +208,22 @@ 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)
))
}
}

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)
)


Expand Down
9 changes: 6 additions & 3 deletions man/annotation_logticks.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions tests/testthat/_snaps/annotate.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

4 changes: 4 additions & 0 deletions tests/testthat/test-annotate.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})

0 comments on commit bde88f8

Please sign in to comment.