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
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
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
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)) +
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+
185207transform_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+
0 commit comments