Skip to content

Commit dbdb7b4

Browse files
committed
resolve merge conflict
Merge branch 'main' into fancy_ggproto_docs # Conflicts: # R/coord-.R # R/scale-.R # man/ggplot2-ggproto.Rd
2 parents 8486ee0 + 7cc5c72 commit dbdb7b4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+768
-507
lines changed

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ export(CoordQuickmap)
168168
export(CoordRadial)
169169
export(CoordSf)
170170
export(CoordTrans)
171+
export(CoordTransform)
171172
export(Facet)
172173
export(FacetGrid)
173174
export(FacetNull)
@@ -322,6 +323,7 @@ export(coord_quickmap)
322323
export(coord_radial)
323324
export(coord_sf)
324325
export(coord_trans)
326+
export(coord_transform)
325327
export(cut_interval)
326328
export(cut_number)
327329
export(cut_width)

NEWS.md

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

3+
* In continuous scales, when `breaks` is a function and `n.breaks` is set, the
4+
`n.breaks` will be passed to the `breaks` function. Previously, `n.breaks`
5+
only applied to the default break calculation (@teunbrand, #5972)
36
* (internal) New `Facet$draw_panel_content()` method for delegating panel
47
assembly (@Yunuuuu, #6406).
58
* Facet gains a new method `setup_panel_params` to interact with the
@@ -280,6 +283,7 @@
280283
(@teunbrand, #5938, #4327).
281284
* Fixed bug where empty discrete scales weren't recognised as such
282285
(@teunbrand, #5945).
286+
* `coord_trans()` renamed to `coord_transform()` (@nmercadeb, #5825).
283287
* (internal) The summary function of `stat_summary()` and `stat_summary_bin()`
284288
is setup once in total instead of once per group (@teunbrand, #5971)
285289
* `facet_grid(space = "free")` can now be combined with `coord_fixed()`

R/annotation-logticks.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#' @param scaled is the data already log-scaled? This should be `TRUE`
2525
#' (default) when the data is already transformed with `log10()` or when
2626
#' using `scale_y_log10()`. It should be `FALSE` when using
27-
#' `coord_trans(y = "log10")`.
27+
#' `coord_transform(y = "log10")`.
2828
#' @param colour Colour of the tick marks.
2929
#' @param linewidth Thickness of tick marks, in mm.
3030
#' @param linetype Linetype of tick marks (`solid`, `dashed`, etc.)
@@ -36,7 +36,7 @@
3636
#' @export
3737
#' @seealso [scale_y_continuous()], [scale_y_log10()] for log scale
3838
#' transformations.
39-
#' @seealso [coord_trans()] for log coordinate transformations.
39+
#' @seealso [coord_transform()] for log coordinate transformations.
4040
#'
4141
#' @examples
4242
#' # Make a log-log plot (without log ticks)
@@ -75,7 +75,7 @@
7575
#' # Using a coordinate transform requires scaled = FALSE
7676
#' t <- ggplot(msleep, aes(bodywt, brainwt)) +
7777
#' geom_point() +
78-
#' coord_trans(x = "log10", y = "log10") +
78+
#' coord_transform(x = "log10", y = "log10") +
7979
#' theme_bw()
8080
#' t + annotation_logticks(scaled = FALSE)
8181
#'

R/coord-.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#' Coords
22
#'
33
#' @description
4-
#' All `coord_*()` functions (like `coord_trans()`) return a `Coord*` object
5-
#' (like `CoordTrans`). These objects contain methods that support the
4+
#' All `coord_*()` functions (like `coord_transform()`) return a `Coord*` object
5+
#' (like `CoordTransform`). These objects contain methods that support the
66
#' coordinate systems in ggplot2.
77
#'
88
#' @details
@@ -422,7 +422,7 @@ Coord <- ggproto("Coord",
422422
#' transformed. It is used in `coord_munch()` to ensure limits are in data
423423
#' coordinates.
424424
#'
425-
#' The back-transformation may be needed for coords such as `coord_trans()`,
425+
#' The back-transformation may be needed for coords such as `coord_transform()`,
426426
#' where the range in the transformed coordinates differs from the range in
427427
#' the untransformed coordinates.
428428
#'

R/coord-cartesian-.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ CoordCartesian <- ggproto("CoordCartesian", Coord,
102102
self$range(panel_params)
103103
},
104104

105-
transform = function(self, data, panel_params) {
106-
reverse <- self$reverse %||% "none"
105+
transform = function(data, panel_params) {
106+
reverse <- panel_params$reverse %||% "none"
107107
x <- panel_params$x[[switch(reverse, xy = , x = "reverse", "rescale")]]
108108
y <- panel_params$y[[switch(reverse, xy = , y = "reverse", "rescale")]]
109109
data <- transform_position(data, x, y)
@@ -113,7 +113,8 @@ CoordCartesian <- ggproto("CoordCartesian", Coord,
113113
setup_panel_params = function(self, scale_x, scale_y, params = list()) {
114114
c(
115115
view_scales_from_scale(scale_x, self$limits$x, params$expand[c(4, 2)]),
116-
view_scales_from_scale(scale_y, self$limits$y, params$expand[c(3, 1)])
116+
view_scales_from_scale(scale_y, self$limits$y, params$expand[c(3, 1)]),
117+
reverse = self$reverse %||% "none"
117118
)
118119
},
119120

R/coord-radial.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ polar_bbox <- function(arc, margin = c(0.05, 0.05, 0.05, 0.05),
524524
return(list(x = c(0, 1), y = c(0, 1)))
525525
}
526526
arc <- sort(arc)
527+
inner_radius <- sort(inner_radius)
527528

528529
# X and Y position of the sector arc ends
529530
xmax <- 0.5 * sin(arc) + 0.5

R/coord-sf.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ CoordSf <- ggproto("CoordSf", CoordCartesian,
8686
target_crs <- panel_params$crs
8787

8888
# CoordSf doesn't use the viewscale rescaling, so we just flip ranges
89-
reverse <- self$reverse %||% "none"
89+
reverse <- panel_params$reverse %||% "none"
9090
x_range <- switch(reverse, xy = , x = rev, identity)(panel_params$x_range)
9191
y_range <- switch(reverse, xy = , y = rev, identity)(panel_params$y_range)
9292

@@ -268,7 +268,8 @@ CoordSf <- ggproto("CoordSf", CoordCartesian,
268268
y_range = y_range,
269269
crs = params$crs,
270270
default_crs = params$default_crs,
271-
!!!viewscales
271+
!!!viewscales,
272+
reverse = self$reverse %||% "none"
272273
)
273274

274275
# Rescale graticule for panel grid

R/coord-transform.R

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
#' Transformed Cartesian coordinate system
22
#'
3-
#' `coord_trans()` is different to scale transformations in that it occurs after
3+
#' `coord_transform()` is different to scale transformations in that it occurs after
44
#' statistical transformation and will affect the visual appearance of geoms - there is
55
#' no guarantee that straight lines will continue to be straight.
66
#'
77
#' Transformations only work with continuous values: see
88
#' [scales::new_transform()] for list of transformations, and instructions
99
#' on how to create your own.
1010
#'
11+
#' The `coord_trans()` function is deprecated in favour of `coord_transform()`.
12+
#'
1113
#' @inheritParams coord_cartesian
1214
#' @param x,y Transformers for x and y axes or their names.
1315
#' @param limx,limy `r lifecycle::badge("deprecated")` use `xlim` and `ylim` instead.
16+
#' @param ... Arguments forwarded to `coord_transform()`.
1417
#' @seealso
1518
#' The `r link_book("coord transformations section", "coord#transformations-with-coord_trans")`
1619
#' @export
@@ -30,7 +33,7 @@
3033
#' # * by transforming the coordinate system:
3134
#' ggplot(diamonds, aes(carat, price)) +
3235
#' geom_point() +
33-
#' coord_trans(x = "log10", y = "log10")
36+
#' coord_transform(x = "log10", y = "log10")
3437
#'
3538
#' # The difference between transforming the scales and
3639
#' # transforming the coordinate system is that scale
@@ -49,7 +52,7 @@
4952
#' ggplot(d, aes(carat, price)) +
5053
#' geom_point() +
5154
#' geom_smooth(method = "lm") +
52-
#' coord_trans(x = "log10", y = "log10")
55+
#' coord_transform(x = "log10", y = "log10")
5356
#'
5457
#' # Here I used a subset of diamonds so that the smoothed line didn't
5558
#' # drop below zero, which obviously causes problems on the log-transformed
@@ -62,7 +65,7 @@
6265
#' geom_smooth(method = "lm") +
6366
#' scale_x_log10() +
6467
#' scale_y_log10() +
65-
#' coord_trans(x = scales::transform_exp(10), y = scales::transform_exp(10))
68+
#' coord_transform(x = scales::transform_exp(10), y = scales::transform_exp(10))
6669
#'
6770
#' # cf.
6871
#' ggplot(diamonds, aes(carat, price)) +
@@ -74,18 +77,18 @@
7477
#' df <- data.frame(a = abs(rnorm(26)),letters)
7578
#' plot <- ggplot(df,aes(a,letters)) + geom_point()
7679
#'
77-
#' plot + coord_trans(x = "log10")
78-
#' plot + coord_trans(x = "sqrt")
80+
#' plot + coord_transform(x = "log10")
81+
#' plot + coord_transform(x = "sqrt")
7982
#' }
80-
coord_trans <- function(x = "identity", y = "identity", xlim = NULL, ylim = NULL,
81-
limx = deprecated(), limy = deprecated(), clip = "on",
82-
expand = TRUE, reverse = "none") {
83+
coord_transform <- function(x = "identity", y = "identity", xlim = NULL, ylim = NULL,
84+
limx = deprecated(), limy = deprecated(), clip = "on",
85+
expand = TRUE, reverse = "none") {
8386
if (lifecycle::is_present(limx)) {
84-
deprecate_warn0("3.3.0", "coord_trans(limx)", "coord_trans(xlim)")
87+
deprecate_warn0("3.3.0", "coord_transform(limx)", "coord_transform(xlim)")
8588
xlim <- limx
8689
}
8790
if (lifecycle::is_present(limy)) {
88-
deprecate_warn0("3.3.0", "coord_trans(limy)", "coord_trans(ylim)")
91+
deprecate_warn0("3.3.0", "coord_transform(limy)", "coord_transform(ylim)")
8992
ylim <- limy
9093
}
9194

@@ -96,7 +99,8 @@ coord_trans <- function(x = "identity", y = "identity", xlim = NULL, ylim = NULL
9699
if (is.character(x)) x <- as.transform(x)
97100
if (is.character(y)) y <- as.transform(y)
98101

99-
ggproto(NULL, CoordTrans,
102+
ggproto(
103+
NULL, CoordTransform,
100104
trans = list(x = x, y = y),
101105
limits = list(x = xlim, y = ylim),
102106
expand = expand,
@@ -105,12 +109,23 @@ coord_trans <- function(x = "identity", y = "identity", xlim = NULL, ylim = NULL
105109
)
106110
}
107111

112+
#' @rdname coord_transform
113+
#' @export
114+
coord_trans <- function(...) {
115+
deprecate_soft0(
116+
"3.5.2",
117+
"coord_trans()",
118+
"coord_transform()"
119+
)
120+
coord_transform(...)
121+
}
108122

109123
#' @rdname Coord
110124
#' @format NULL
111125
#' @usage NULL
112126
#' @export
113-
CoordTrans <- ggproto("CoordTrans", Coord,
127+
CoordTransform <- ggproto(
128+
"CoordTransform", Coord,
114129
is_free = function() TRUE,
115130
distance = function(self, x, y, panel_params) {
116131
max_dist <- dist_euclidean(panel_params$x.range, panel_params$y.range)
@@ -134,7 +149,7 @@ CoordTrans <- ggproto("CoordTrans", Coord,
134149
transform = function(self, data, panel_params) {
135150
# trans_x() and trans_y() needs to keep Inf values because this can be called
136151
# in guide_transform.axis()
137-
reverse <- self$reverse %||% "none"
152+
reverse <- panel_params$reverse %||% "none"
138153
x_range <- switch(reverse, xy = , x = rev, identity)(panel_params$x.range)
139154
y_range <- switch(reverse, xy = , y = rev, identity)(panel_params$y.range)
140155
trans_x <- function(data) {
@@ -159,7 +174,8 @@ CoordTrans <- ggproto("CoordTrans", Coord,
159174
setup_panel_params = function(self, scale_x, scale_y, params = list()) {
160175
c(
161176
view_scales_from_scale_with_coord_trans(scale_x, self$limits$x, self$trans$x, params$expand[c(4, 2)]),
162-
view_scales_from_scale_with_coord_trans(scale_y, self$limits$y, self$trans$y, params$expand[c(3, 1)])
177+
view_scales_from_scale_with_coord_trans(scale_y, self$limits$y, self$trans$y, params$expand[c(3, 1)]),
178+
reverse = self$reverse %||% "none"
163179
)
164180
},
165181

@@ -182,6 +198,13 @@ CoordTrans <- ggproto("CoordTrans", Coord,
182198
}
183199
)
184200

201+
# TODO: deprecate this some time in the future
202+
#' @rdname ggplot2-ggproto
203+
#' @format NULL
204+
#' @usage NULL
205+
#' @export
206+
CoordTrans <- ggproto("CoordTrans", CoordTransform)
207+
185208
transform_value <- function(trans, value, range) {
186209
if (is.null(value))
187210
return(value)
@@ -257,3 +280,4 @@ warn_new_infinites <- function(old_values, new_values, axis, call = caller_env()
257280
cli::cli_warn("Transformation introduced infinite values in {axis}-axis", call = call)
258281
}
259282
}
283+

R/geom-contour.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#' once. Missing values of `z` are allowed, but contouring will only work for
1010
#' grid points where all four corners are non-missing. If you have irregular
1111
#' data, you'll need to first interpolate on to a grid before visualising,
12-
#' using [interp::interp()], [akima::bilinear()], or similar.
12+
#' using `interp::interp()`, `akima::bilinear()`, or similar.
1313
#'
1414
#' @eval rd_aesthetics("geom", "contour")
1515
#' @eval rd_aesthetics("geom", "contour_filled")

R/geom-histogram.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@
113113
#' # no observations have 0 ratings.
114114
#' m +
115115
#' geom_histogram(boundary = 0) +
116-
#' coord_trans(x = "log10")
116+
#' coord_transform(x = "log10")
117117
#' # Use boundary = 0, to make sure we don't take sqrt of negative values
118118
#' m +
119119
#' geom_histogram(boundary = 0) +
120-
#' coord_trans(x = "sqrt")
120+
#' coord_transform(x = "sqrt")
121121
#'
122122
#' # You can also transform the y axis. Remember that the base of the bars
123123
#' # has value 0, so log transformations are not appropriate

0 commit comments

Comments
 (0)