1
1
# ' Transformed Cartesian coordinate system
2
2
# '
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
4
4
# ' statistical transformation and will affect the visual appearance of geoms - there is
5
5
# ' no guarantee that straight lines will continue to be straight.
6
6
# '
7
7
# ' Transformations only work with continuous values: see
8
8
# ' [scales::new_transform()] for list of transformations, and instructions
9
9
# ' on how to create your own.
10
10
# '
11
+ # ' The `coord_trans()` function is deprecated in favour of `coord_transform()`.
12
+ # '
11
13
# ' @inheritParams coord_cartesian
12
14
# ' @param x,y Transformers for x and y axes or their names.
13
15
# ' @param limx,limy `r lifecycle::badge("deprecated")` use `xlim` and `ylim` instead.
16
+ # ' @param ... Arguments forwarded to `coord_transform()`.
14
17
# ' @seealso
15
18
# ' The `r link_book("coord transformations section", "coord#transformations-with-coord_trans")`
16
19
# ' @export
30
33
# ' # * by transforming the coordinate system:
31
34
# ' ggplot(diamonds, aes(carat, price)) +
32
35
# ' geom_point() +
33
- # ' coord_trans (x = "log10", y = "log10")
36
+ # ' coord_transform (x = "log10", y = "log10")
34
37
# '
35
38
# ' # The difference between transforming the scales and
36
39
# ' # transforming the coordinate system is that scale
49
52
# ' ggplot(d, aes(carat, price)) +
50
53
# ' geom_point() +
51
54
# ' geom_smooth(method = "lm") +
52
- # ' coord_trans (x = "log10", y = "log10")
55
+ # ' coord_transform (x = "log10", y = "log10")
53
56
# '
54
57
# ' # Here I used a subset of diamonds so that the smoothed line didn't
55
58
# ' # drop below zero, which obviously causes problems on the log-transformed
62
65
# ' geom_smooth(method = "lm") +
63
66
# ' scale_x_log10() +
64
67
# ' 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))
66
69
# '
67
70
# ' # cf.
68
71
# ' ggplot(diamonds, aes(carat, price)) +
74
77
# ' df <- data.frame(a = abs(rnorm(26)),letters)
75
78
# ' plot <- ggplot(df,aes(a,letters)) + geom_point()
76
79
# '
77
- # ' plot + coord_trans (x = "log10")
78
- # ' plot + coord_trans (x = "sqrt")
80
+ # ' plot + coord_transform (x = "log10")
81
+ # ' plot + coord_transform (x = "sqrt")
79
82
# ' }
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" ) {
83
86
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)" )
85
88
xlim <- limx
86
89
}
87
90
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)" )
89
92
ylim <- limy
90
93
}
91
94
@@ -96,7 +99,8 @@ coord_trans <- function(x = "identity", y = "identity", xlim = NULL, ylim = NULL
96
99
if (is.character(x )) x <- as.transform(x )
97
100
if (is.character(y )) y <- as.transform(y )
98
101
99
- ggproto(NULL , CoordTrans ,
102
+ ggproto(
103
+ NULL , CoordTransform ,
100
104
trans = list (x = x , y = y ),
101
105
limits = list (x = xlim , y = ylim ),
102
106
expand = expand ,
@@ -105,12 +109,23 @@ coord_trans <- function(x = "identity", y = "identity", xlim = NULL, ylim = NULL
105
109
)
106
110
}
107
111
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
+ }
108
122
109
123
# ' @rdname ggplot2-ggproto
110
124
# ' @format NULL
111
125
# ' @usage NULL
112
126
# ' @export
113
- CoordTrans <- ggproto(" CoordTrans" , Coord ,
127
+ CoordTransform <- ggproto(
128
+ " CoordTransform" , Coord ,
114
129
is_free = function () TRUE ,
115
130
distance = function (self , x , y , panel_params ) {
116
131
max_dist <- dist_euclidean(panel_params $ x.range , panel_params $ y.range )
@@ -182,6 +197,13 @@ CoordTrans <- ggproto("CoordTrans", Coord,
182
197
}
183
198
)
184
199
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
+
185
207
transform_value <- function (trans , value , range ) {
186
208
if (is.null(value ))
187
209
return (value )
@@ -257,3 +279,4 @@ warn_new_infinites <- function(old_values, new_values, axis, call = caller_env()
257
279
cli :: cli_warn(" Transformation introduced infinite values in {axis}-axis" , call = call )
258
280
}
259
281
}
282
+
0 commit comments