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