Skip to content

Commit bde88f8

Browse files
authored
Convert size -> linewidth in annotation_logticks() (#5330)
1 parent da2a8e8 commit bde88f8

File tree

5 files changed

+33
-12
lines changed

5 files changed

+33
-12
lines changed

NEWS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# ggplot2 (development version)
22

3+
* The `size` argument in `annotation_logticks()` has been deprecated in favour
4+
of the `linewidth` argument (#5292).
5+
36
* `geom_boxplot()` gains an `outliers` argument to switch outliers on or off,
47
in a manner that does affects the scale range. For hiding outliers that does
58
not affect the scale range, you can continue to use `outlier.shape = NA`
@@ -14,7 +17,6 @@
1417
deprecated. The `hjust` setting of the `legend.text` and `legend.title`
1518
elements continues to fulfil the role of text alignment (@teunbrand, #5347).
1619

17-
1820
* Integers are once again valid input to theme arguments that expect numeric
1921
input (@teunbrand, #5369)
2022

R/annotation-logticks.R

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
#' using `scale_y_log10()`. It should be `FALSE` when using
2222
#' `coord_trans(y = "log10")`.
2323
#' @param colour Colour of the tick marks.
24-
#' @param size Thickness of tick marks, in mm.
24+
#' @param linewidth Thickness of tick marks, in mm.
2525
#' @param linetype Linetype of tick marks (`solid`, `dashed`, etc.)
2626
#' @param alpha The transparency of the tick marks.
2727
#' @param color An alias for `colour`.
2828
#' @param ... Other parameters passed on to the layer
29+
#' @param size `r lifecycle::badge("deprecated")`
2930
#'
3031
#' @export
3132
#' @seealso [scale_y_continuous()], [scale_y_log10()] for log scale
@@ -81,11 +82,17 @@
8182
#' )
8283
annotation_logticks <- function(base = 10, sides = "bl", outside = FALSE, scaled = TRUE,
8384
short = unit(0.1, "cm"), mid = unit(0.2, "cm"), long = unit(0.3, "cm"),
84-
colour = "black", size = 0.5, linetype = 1, alpha = 1, color = NULL, ...)
85+
colour = "black", linewidth = 0.5, linetype = 1, alpha = 1, color = NULL, ...,
86+
size = deprecated())
8587
{
8688
if (!is.null(color))
8789
colour <- color
8890

91+
if (lifecycle::is_present(size)) {
92+
deprecate_soft0("3.5.0", I("Using the `size` aesthetic in this geom"), I("`linewidth`"))
93+
linewidth <- linewidth %||% size
94+
}
95+
8996
layer(
9097
data = dummy_data(),
9198
mapping = NULL,
@@ -103,7 +110,7 @@ annotation_logticks <- function(base = 10, sides = "bl", outside = FALSE, scaled
103110
mid = mid,
104111
long = long,
105112
colour = colour,
106-
size = size,
113+
linewidth = linewidth,
107114
linetype = linetype,
108115
alpha = alpha,
109116
...
@@ -163,14 +170,14 @@ GeomLogticks <- ggproto("GeomLogticks", Geom,
163170
ticks$x_b <- with(data, segmentsGrob(
164171
x0 = unit(xticks$x, "native"), x1 = unit(xticks$x, "native"),
165172
y0 = unit(xticks$start, "cm"), y1 = unit(xticks$end, "cm"),
166-
gp = gpar(col = alpha(colour, alpha), lty = linetype, lwd = size * .pt)
173+
gp = gpar(col = alpha(colour, alpha), lty = linetype, lwd = linewidth * .pt)
167174
))
168175
}
169176
if (grepl("t", sides) && nrow(xticks) > 0) {
170177
ticks$x_t <- with(data, segmentsGrob(
171178
x0 = unit(xticks$x, "native"), x1 = unit(xticks$x, "native"),
172179
y0 = unit(1, "npc") - unit(xticks$start, "cm"), y1 = unit(1, "npc") - unit(xticks$end, "cm"),
173-
gp = gpar(col = alpha(colour, alpha), lty = linetype, lwd = size * .pt)
180+
gp = gpar(col = alpha(colour, alpha), lty = linetype, lwd = linewidth * .pt)
174181
))
175182
}
176183
}
@@ -201,22 +208,22 @@ GeomLogticks <- ggproto("GeomLogticks", Geom,
201208
ticks$y_l <- with(data, segmentsGrob(
202209
y0 = unit(yticks$y, "native"), y1 = unit(yticks$y, "native"),
203210
x0 = unit(yticks$start, "cm"), x1 = unit(yticks$end, "cm"),
204-
gp = gpar(col = alpha(colour, alpha), lty = linetype, lwd = size * .pt)
211+
gp = gpar(col = alpha(colour, alpha), lty = linetype, lwd = linewidth * .pt)
205212
))
206213
}
207214
if (grepl("r", sides) && nrow(yticks) > 0) {
208215
ticks$y_r <- with(data, segmentsGrob(
209216
y0 = unit(yticks$y, "native"), y1 = unit(yticks$y, "native"),
210217
x0 = unit(1, "npc") - unit(yticks$start, "cm"), x1 = unit(1, "npc") - unit(yticks$end, "cm"),
211-
gp = gpar(col = alpha(colour, alpha), lty = linetype, lwd = size * .pt)
218+
gp = gpar(col = alpha(colour, alpha), lty = linetype, lwd = linewidth * .pt)
212219
))
213220
}
214221
}
215222

216223
gTree(children = inject(gList(!!!ticks)))
217224
},
218225

219-
default_aes = aes(colour = "black", size = 0.5, linetype = 1, alpha = 1)
226+
default_aes = aes(colour = "black", linewidth = 0.5, linetype = 1, alpha = 1)
220227
)
221228

222229

man/annotation_logticks.Rd

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/_snaps/annotate.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,8 @@
2929

3030
Unequal parameter lengths: x (3), y (3), and fill (2)
3131

32+
# annotation_logticks warns about deprecated `size` argument
33+
34+
Using the `size` aesthetic in this geom was deprecated in ggplot2 3.5.0.
35+
i Please use `linewidth` instead.
36+

tests/testthat/test-annotate.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,7 @@ test_that("unsupported geoms signal a warning (#4719)", {
7777
test_that("annotate() checks aesthetic lengths match", {
7878
expect_snapshot_error(annotate("point", 1:3, 1:3, fill = c('red', 'black')))
7979
})
80+
81+
test_that("annotation_logticks warns about deprecated `size` argument", {
82+
expect_snapshot_warning(annotation_logticks(size = 5))
83+
})

0 commit comments

Comments
 (0)