Skip to content

Commit 8639ee8

Browse files
nmercadebteunbrand
andauthored
Rename coord_trans() to coord_transform() (#6046)
* rename coord_trans to coord_transform, issue #5825 * Update _pkgdown.yml * add deprecated function to pkgdown * revert NEWS.md revision * simplify alias * class alias * reoxygenate * remove duplicate news entries --------- Co-authored-by: Teun van den Brand <[email protected]> Co-authored-by: Teun van den Brand <[email protected]>
1 parent 86b32ce commit 8639ee8

28 files changed

+119
-84
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@
280280
(@teunbrand, #5938, #4327).
281281
* Fixed bug where empty discrete scales weren't recognised as such
282282
(@teunbrand, #5945).
283+
* `coord_trans()` renamed to `coord_transform()` (@nmercadeb, #5825).
283284
* (internal) The summary function of `stat_summary()` and `stat_summary_bin()`
284285
is setup once in total instead of once per group (@teunbrand, #5971)
285286
* `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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#' @section Coordinate systems:
22
#'
3-
#' All `coord_*()` functions (like `coord_trans()`) return a `Coord*`
3+
#' All `coord_*()` functions (like `coord_transform()`) return a `Coord*`
44
#' object (like `CoordTrans`).
55
#'
66
#' Each of the `Coord*` objects is a [ggproto()] object,
@@ -16,7 +16,7 @@
1616
#' - `backtransform_range(panel_params)`: Extracts the panel range provided
1717
#' in `panel_params` (created by `setup_panel_params()`, see below) and
1818
#' back-transforms to data coordinates. This back-transformation can be needed
19-
#' for coords such as `coord_trans()` where the range in the transformed
19+
#' for coords such as `coord_transform()` where the range in the transformed
2020
#' coordinates differs from the range in the untransformed coordinates. Returns
2121
#' a list of two ranges, `x` and `y`, and these correspond to the variables
2222
#' mapped to the `x` and `y` aesthetics, even for coords such as `coord_flip()`

R/coord-transform.R

Lines changed: 36 additions & 13 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 ggplot2-ggproto
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)
@@ -182,6 +197,13 @@ CoordTrans <- ggproto("CoordTrans", Coord,
182197
}
183198
)
184199

200+
# TODO: deprecate this some time in the future
201+
#' @rdname ggplot2-ggproto
202+
#' @format NULL
203+
#' @usage NULL
204+
#' @export
205+
CoordTrans <- ggproto("CoordTrans", CoordTransform)
206+
185207
transform_value <- function(trans, value, range) {
186208
if (is.null(value))
187209
return(value)
@@ -257,3 +279,4 @@ warn_new_infinites <- function(old_values, new_values, axis, call = caller_env()
257279
cli::cli_warn("Transformation introduced infinite values in {axis}-axis", call = call)
258280
}
259281
}
282+

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

R/geom-violin.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@
7979
#' scale_y_log10()
8080
#' m +
8181
#' geom_violin() +
82-
#' coord_trans(y = "log10")
82+
#' coord_transform(y = "log10")
8383
#' m +
8484
#' geom_violin() +
85-
#' scale_y_log10() + coord_trans(y = "log10")
85+
#' scale_y_log10() + coord_transform(y = "log10")
8686
#'
8787
#' # Violin plots with continuous x:
8888
#' # Use the group aesthetic to group observations in violins

R/guide-axis-logticks.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ NULL
1313
#' @param prescale.base Base of logarithm used to transform data manually. The
1414
#' default, `NULL`, will use the scale transformation to calculate positions.
1515
#' Only set `prescale.base` if the data has already been log-transformed.
16-
#' When using a log-transform in the position scale or in `coord_trans()`,
16+
#' When using a log-transform in the position scale or in `coord_transform()`,
1717
#' keep the default `NULL` argument.
1818
#' @param negative.small When the scale limits include 0 or negative numbers,
1919
#' what should be the smallest absolute value that is marked with a tick?
@@ -39,7 +39,7 @@ NULL
3939
#' scale_y_log10(guide = "axis_logticks")
4040
#'
4141
#' # Or with log-transformed coordinates
42-
#' p + coord_trans(x = "log10", y = "log10") +
42+
#' p + coord_transform(x = "log10", y = "log10") +
4343
#' guides(x = "axis_logticks", y = "axis_logticks")
4444
#'
4545
#' # When data is transformed manually, one should provide `prescale.base`

R/stat-summary.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
#' # statistic has been computed. This means we're calculating the summary on the raw data
124124
#' # and stretching the geoms onto the log scale. Compare the widths of the
125125
#' # standard errors.
126-
#' m2 + coord_trans(y="log10")
126+
#' m2 + coord_transform(y="log10")
127127
#' }
128128
#' }
129129
stat_summary <- function(mapping = NULL, data = NULL,

R/summarise-plot.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#' @section Coord summary:
3434
#'
3535
#' The function `summarise_coord()` returns information about the log base for
36-
#' coordinates that are log-transformed in `coord_trans()`, and it also indicates
36+
#' coordinates that are log-transformed in `coord_transform()`, and it also indicates
3737
#' whether the coord has flipped the x and y axes.
3838
#'
3939
#' @section Layer summary:

_pkgdown.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,15 @@ reference:
166166
The coordinate system determines how the `x` and `y` aesthetics combine
167167
to position elements in the plot. The default coordinate system is
168168
Cartesian (`coord_cartesian()`), which can be tweaked with `coord_map()`,
169-
`coord_fixed()`, `coord_flip()`, and `coord_trans()`, or completely
169+
`coord_fixed()`, `coord_flip()`, and `coord_transform()`, or completely
170170
replaced with `coord_polar()`.
171171
contents:
172172
- coord_cartesian
173173
- coord_fixed
174174
- coord_flip
175175
- coord_map
176176
- coord_polar
177+
- coord_transform
177178
- coord_trans
178179

179180
- title: Themes

man/annotation_logticks.Rd

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

man/coord_trans.Rd renamed to man/coord_transform.Rd

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

man/geom_histogram.Rd

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

0 commit comments

Comments
 (0)