Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e4b065b
switch `trans` -> `transform` in constructors
teunbrand Dec 4, 2023
ddd8084
swap `trans` -> `transform` in secondary axes
teunbrand Dec 4, 2023
4cb5c61
migrate `trans` -> `transform` in scale functions
teunbrand Dec 4, 2023
84b54c8
propagate `trans` -> `transform` in other functions
teunbrand Dec 4, 2023
190ba17
adjust test verbiage
teunbrand Dec 4, 2023
43606d3
reoxygenate
teunbrand Dec 4, 2023
986373b
add news bullet
teunbrand Dec 4, 2023
b2f5ecc
document sec axis
teunbrand Dec 4, 2023
a121505
don't namespace deprecated
teunbrand Dec 5, 2023
2278ca4
Merge branch 'main' into trans_to_transform
teunbrand Dec 5, 2023
a5ad41c
Merge branch 'main' into trans_to_transform
teunbrand Dec 5, 2023
d34cfde
rename trans field
teunbrand Dec 6, 2023
7bbe90c
Merge branch 'trans_to_transform' of https://github.com/teunbrand/ggp…
teunbrand Dec 6, 2023
1a2335d
Merge branch 'main' into trans_to_transform
teunbrand Dec 6, 2023
398158a
fix sec axis bug
teunbrand Dec 6, 2023
69656fd
resolve merge conflict
teunbrand Dec 11, 2023
2e31c0e
fallback mechanism
teunbrand Dec 11, 2023
7940355
deprecation message
teunbrand Dec 11, 2023
3d55f85
transformer -> transformation
teunbrand Dec 11, 2023
a98974e
rename `AxisSecondary$trans` slot
teunbrand Dec 11, 2023
9842121
Implement `get_transformation()` method
teunbrand Dec 14, 2023
adbdb40
Use `get_transformation()`
teunbrand Dec 14, 2023
0b47ab4
Merge branch 'main' into trans_to_transform
teunbrand Dec 14, 2023
8cf9cd1
Document `get_transformation()` method
teunbrand Dec 14, 2023
f3901c8
Merge branch 'trans_to_transform' of https://github.com/teunbrand/ggp…
teunbrand Dec 14, 2023
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
21 changes: 21 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@

* The `trans` argument in scales and secondary axes has been renamed to
`transform`. The `trans` argument itself is deprecated (#5558).
* When legend titles are larger than the legend, title justification extends
to the placement of keys and labels (#1903).

* `draw_key_label()` now better reflects the appearance of labels.

* The `minor_breaks` function argument in scales can now take a function with
two arguments: the scale's limits and the scale's major breaks (#3583).

* (internal) The `ScaleContinuous$get_breaks()` method no longer censors
the computed breaks.

* Plot scales now ignore `AsIs` objects constructed with `I(x)`, instead of
invoking the identity scale. This allows these columns to co-exist with other
layers that need a non-identity scale for the same aesthetic. Also, it makes
it easy to specify relative positions (@teunbrand, #5142).

* The `fill` aesthetic in many geoms now accepts grid's patterns and gradients.
For developers of layer extensions, this feature can be enabled by switching
from `fill = alpha(fill, alpha)` to `fill = fill_alpha(fill, alpha)` when
providing fills to `grid::gpar()` (@teunbrand, #3997).

* The plot's title, subtitle and caption now obey horizontal text margins
(#5533).

Expand Down
20 changes: 10 additions & 10 deletions R/axis-secondary.R
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,
}
if (is.derived(self$name) && !is.waive(scale$name)) self$name <- scale$name
if (is.derived(self$breaks)) self$breaks <- scale$breaks
if (is.waive(self$breaks)) self$breaks <- scale$transformer$breaks
if (is.waive(self$breaks)) self$breaks <- scale$transformation$breaks
if (is.derived(self$labels)) self$labels <- scale$labels
if (is.derived(self$guide)) self$guide <- scale$guide
},
Expand All @@ -195,9 +195,9 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,
return()
}

transformer <- scale$transformer
transformation <- scale$transformation %||% scale$trans
along_range <- seq(range[1], range[2], length.out = self$detail)
old_range <- transformer$inverse(along_range)
old_range <- transformation$inverse(along_range)

# Create mapping between primary and secondary range
full_range <- self$transform_range(old_range)
Expand All @@ -214,9 +214,9 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,
self$mono_test(scale)

# Get scale's original range before transformation
transformer <- scale$transformer
transformation <- scale$transformation %||% scale$trans
along_range <- seq(range[1], range[2], length.out = self$detail)
old_range <- transformer$inverse(along_range)
old_range <- transformation$inverse(along_range)

# Create mapping between primary and secondary range
full_range <- self$transform_range(old_range)
Expand All @@ -236,8 +236,8 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,

# patch for date and datetime scales just to maintain functionality
# works only for linear secondary transforms that respect the time or date transform
if (transformer$name %in% c("date", "time")) {
temp_scale <- self$create_scale(new_range, trans = transformer)
if (transformation$name %in% c("date", "time")) {
temp_scale <- self$create_scale(new_range, trans = transformation)
range_info <- temp_scale$break_info()
old_val_trans <- rescale(range_info$major, from = c(0, 1), to = range)
old_val_minor_trans <- rescale(range_info$minor, from = c(0, 1), to = range)
Expand All @@ -248,7 +248,7 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,
# Map the break values back to their correct position on the primary scale
if (!is.null(range_info$major_source)) {
old_val <- stats::approx(full_range, old_range, range_info$major_source)$y
old_val_trans <- transformer$transform(old_val)
old_val_trans <- transformation$transform(old_val)

# rescale values from 0 to 1
range_info$major[] <- round(
Expand All @@ -264,7 +264,7 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,

if (!is.null(range_info$minor_source)) {
old_val_minor <- stats::approx(full_range, old_range, range_info$minor_source)$y
old_val_minor_trans <- transformer$transform(old_val_minor)
old_val_minor_trans <- transformation$transform(old_val_minor)

range_info$minor[] <- round(
rescale(
Expand Down Expand Up @@ -298,7 +298,7 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,
labels = self$labels,
limits = range,
expand = c(0, 0),
transformer = trans
transformation = trans
)
scale$train(range)
scale
Expand Down
6 changes: 3 additions & 3 deletions R/coord-transform.R
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ transform_value <- function(trans, value, range) {
# TODO: can we merge this with view_scales_from_scale()?
view_scales_from_scale_with_coord_trans <- function(scale, coord_limits, trans, expand = TRUE) {
expansion <- default_expansion(scale, expand = expand)
transformer <- scale$transformer %||% transform_identity()
coord_limits <- coord_limits %||% transformer$inverse(c(NA, NA))
transformation <- scale$transformation %||% scale$trans %||% transform_identity()
coord_limits <- coord_limits %||% transformation$inverse(c(NA, NA))
scale_limits <- scale$get_limits()

if (scale$is_discrete()) {
Expand All @@ -204,7 +204,7 @@ view_scales_from_scale_with_coord_trans <- function(scale, coord_limits, trans,
)
} else {
# transform user-specified limits to scale transformed space
coord_limits <- transformer$transform(coord_limits)
coord_limits <- transformation$transform(coord_limits)
continuous_ranges <- expand_limits_continuous_trans(
scale_limits,
expansion,
Expand Down
10 changes: 5 additions & 5 deletions R/guide-axis-logticks.R
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,20 @@ GuideAxisLogticks <- ggproto(

# Reconstruct a transformation if user has prescaled data
if (!is.null(params$prescale_base)) {
trans_name <- scale$scale$transformer$name
trans_name <- scale$scale$transformation$name
if (trans_name != "identity") {
cli::cli_warn(paste0(
"The {.arg prescale_base} argument will override the scale's ",
"{.field {trans_name}} transformation in log-tick positioning."
))
}
transformer <- transform_log(base = params$prescale_base)
transformation <- transform_log(base = params$prescale_base)
} else {
transformer <- scale$scale$transformer
transformation <- scale$scale$transformation %||% scale$scale$trans
}

# Reconstruct original range
limits <- transformer$inverse(scale$get_limits())
limits <- transformation$inverse(scale$get_limits())
has_negatives <- any(limits <= 0)

if (!has_negatives) {
Expand Down Expand Up @@ -188,7 +188,7 @@ GuideAxisLogticks <- ggproto(
}

# Set ticks back into transformed space
ticks <- transformer$transform(c(tens, fives, ones))
ticks <- transformation$transform(c(tens, fives, ones))
nticks <- c(length(tens), length(fives), length(ones))

logkey <- data_frame0(
Expand Down
Loading