Skip to content

Commit

Permalink
refactor: Deprecated 'trans' for new 'transform'
Browse files Browse the repository at this point in the history
* In line with upstream changes in `{ggplot2}` the `trans` argument has been deprecated in various scales functions.
  Use the new `transform` argument instead (#113).
* Several (continuous) scales now have an `...` argument which will passed onto `ggplot2::continuous_scale()`.
* We now import {lifecycle} to help mark these deprecations but since
  {ggplot2} imports {lifecycle} and we import {ggplot2} this isn't a new de facto dependency.

closes #113
  • Loading branch information
trevorld committed Apr 18, 2024
1 parent 3d467ff commit e0fd453
Show file tree
Hide file tree
Showing 12 changed files with 477 additions and 253 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: ggpattern
Type: Package
Title: 'ggplot2' Pattern Geoms
Version: 1.1.0-5
Version: 1.1.0-6
Authors@R: c(person("Mike", "FC", role = "aut"),
person("Trevor L.", "Davis", role = c("aut", "cre"),
email = "trevor.l.davis@gmail.com",
Expand All @@ -19,6 +19,7 @@ Imports:
glue,
grid,
gridpattern (>= 1.2.0),
lifecycle,
rlang,
scales,
Suggests:
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ importFrom(grDevices,col2rgb)
importFrom(grDevices,dev.off)
importFrom(grDevices,png)
importFrom(grDevices,rgb)
importFrom(lifecycle,deprecated)
importFrom(stats,setNames)
importFrom(utils,head)
importFrom(utils,tail)
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
actual aspect ratio (instead of 1).
This may cause your legends to `geom_sf_pattern()` to look different.

## Deprecated features

* In line with upstream changes in `{ggplot2}` the `trans` argument has been deprecated in various scales functions.
Use the new `transform` argument instead (#113).

## New features

* `geom_bar_pattern()` and `geom_col_pattern()` now accept argument `just`.
Expand All @@ -26,6 +31,7 @@

* `draw_key_boxplot_pattern()`, `draw_key_crossbar_pattern()`, and `draw_key_polygon_pattern()` `aspect_ratio` argument
now defaults to `get_aspect_ratio()`.
* Several (continuous) scales now have an `...` argument which will be passed to `ggplot2::continuous_scale()`.

# ggpattern 1.0.1

Expand Down
31 changes: 11 additions & 20 deletions R/scale-pattern-size.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#-----------------------------------------------------------------------------
#' Scales for area or radius
#'
#' @param name,breaks,labels,limits,trans,guide See \code{ggplot2::scale_size} for more information
#' @param name,breaks,labels,limits,trans,guide,...,transform See [ggplot2::scale_size()] for more information
#' @param range a numeric vector of length 2 that specifies the minimum and
#' maximum size of the plotting symbol after transformation.
#' @return A [ggplot2::Scale] object.
Expand Down Expand Up @@ -33,10 +33,17 @@
#-----------------------------------------------------------------------------
scale_pattern_size_continuous <- function(name = waiver(), breaks = waiver(), labels = waiver(),
limits = NULL, range = c(1, 6),
trans = "identity", guide = "legend") {
trans = deprecated(), guide = "legend",
..., transform = "identity") {
if (lifecycle::is_present(trans)) {{
lifecycle::deprecate_warn('1.1.1',
'scale_pattern_size_continuous(trans)',
'scale_pattern_size_continuous(transform)')
transform <- trans
}}
continuous_scale("pattern_size", palette = area_pal(range), name = name,
breaks = breaks, labels = labels, limits = limits, trans = trans,
guide = guide)
breaks = breaks, labels = labels, limits = limits, transform = transform,
guide = guide, ...)
}

#-----------------------------------------------------------------------------
Expand All @@ -45,31 +52,15 @@ scale_pattern_size_continuous <- function(name = waiver(), breaks = waiver(), la
#-----------------------------------------------------------------------------
scale_pattern_size <- scale_pattern_size_continuous


# #-----------------------------------------------------------------------------
# #' @rdname scale_pattern_size_continuous
# #' @export
# #-----------------------------------------------------------------------------
# scale_size_binned <- function(name = waiver(), breaks = waiver(), labels = waiver(),
# limits = NULL, range = c(1, 6), n.breaks = NULL,
# nice.breaks = TRUE, trans = "identity", guide = "bins") {
# binned_scale("size", palette = area_pal(range), name = name,
# breaks = breaks, labels = labels, limits = limits, trans = trans,
# n.breaks = n.breaks, nice.breaks = nice.breaks, guide = guide)
# }


#-----------------------------------------------------------------------------
#' @rdname scale_pattern_size_continuous
#' @export
#' @usage NULL
#-----------------------------------------------------------------------------
scale_pattern_size_discrete <- function(...) {
# warn("Using pattern_size for a discrete variable is not advised.")
scale_pattern_size_ordinal(...)
}


#-----------------------------------------------------------------------------
#' @rdname scale_pattern_size_continuous
#' @export
Expand Down
Loading

0 comments on commit e0fd453

Please sign in to comment.