Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert size -> linewidth in annotation_logticks() #5330

Merged
merged 2 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions 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).

* `coord_sf()` now uses customisable guides provided in the scales or
`guides()` function (@teunbrand).

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