|
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 |
@@ -103,99 +106,15 @@ coord_transform <- function(x = "identity", y = "identity", xlim = NULL, ylim = |
103 | 106 | ) |
104 | 107 | } |
105 | 108 |
|
106 | | -#' Transformed Cartesian coordinate system |
107 | | -#' |
108 | | -#' `r lifecycle::badge("deprecated")` |
109 | | -#' |
110 | | -#' `coord_trans()` is different to scale transformations in that it occurs after |
111 | | -#' statistical transformation and will affect the visual appearance of geoms - there is |
112 | | -#' no guarantee that straight lines will continue to be straight. |
113 | | -#' |
114 | | -#' Transformations only work with continuous values: see |
115 | | -#' [scales::new_transform()] for list of transformations, and instructions |
116 | | -#' on how to create your own. |
117 | | -#' |
118 | | -#' @inheritParams coord_cartesian |
119 | | -#' @param x,y Transformers for x and y axes or their names. |
120 | | -#' @param limx,limy `r lifecycle::badge("deprecated")` use `xlim` and `ylim` instead. |
121 | | -#' @seealso |
122 | | -#' The `r link_book("coord transformations section", "coord#transformations-with-coord_trans")` |
| 109 | +#' @rdname coord_transform |
123 | 110 | #' @export |
124 | | -#' @examples |
125 | | -#' \donttest{ |
126 | | -#' # See ?geom_boxplot for other examples |
127 | | -#' |
128 | | -#' # Three ways of doing transformation in ggplot: |
129 | | -#' # * by transforming the data |
130 | | -#' ggplot(diamonds, aes(log10(carat), log10(price))) + |
131 | | -#' geom_point() |
132 | | -#' # * by transforming the scales |
133 | | -#' ggplot(diamonds, aes(carat, price)) + |
134 | | -#' geom_point() + |
135 | | -#' scale_x_log10() + |
136 | | -#' scale_y_log10() |
137 | | -#' # * by transforming the coordinate system: |
138 | | -#' ggplot(diamonds, aes(carat, price)) + |
139 | | -#' geom_point() + |
140 | | -#' coord_trans(x = "log10", y = "log10") |
141 | | -#' |
142 | | -#' # The difference between transforming the scales and |
143 | | -#' # transforming the coordinate system is that scale |
144 | | -#' # transformation occurs BEFORE statistics, and coordinate |
145 | | -#' # transformation afterwards. Coordinate transformation also |
146 | | -#' # changes the shape of geoms: |
147 | | -#' |
148 | | -#' d <- subset(diamonds, carat > 0.5) |
149 | | -#' |
150 | | -#' ggplot(d, aes(carat, price)) + |
151 | | -#' geom_point() + |
152 | | -#' geom_smooth(method = "lm") + |
153 | | -#' scale_x_log10() + |
154 | | -#' scale_y_log10() |
155 | | -#' |
156 | | -#' ggplot(d, aes(carat, price)) + |
157 | | -#' geom_point() + |
158 | | -#' geom_smooth(method = "lm") + |
159 | | -#' coord_trans(x = "log10", y = "log10") |
160 | | -#' |
161 | | -#' # Here I used a subset of diamonds so that the smoothed line didn't |
162 | | -#' # drop below zero, which obviously causes problems on the log-transformed |
163 | | -#' # scale |
164 | | -#' |
165 | | -#' # With a combination of scale and coordinate transformation, it's |
166 | | -#' # possible to do back-transformations: |
167 | | -#' ggplot(diamonds, aes(carat, price)) + |
168 | | -#' geom_point() + |
169 | | -#' geom_smooth(method = "lm") + |
170 | | -#' scale_x_log10() + |
171 | | -#' scale_y_log10() + |
172 | | -#' coord_trans(x = scales::transform_exp(10), y = scales::transform_exp(10)) |
173 | | -#' |
174 | | -#' # cf. |
175 | | -#' ggplot(diamonds, aes(carat, price)) + |
176 | | -#' geom_point() + |
177 | | -#' geom_smooth(method = "lm") |
178 | | -#' |
179 | | -#' # Also works with discrete scales |
180 | | -#' set.seed(1) |
181 | | -#' df <- data.frame(a = abs(rnorm(26)),letters) |
182 | | -#' plot <- ggplot(df,aes(a,letters)) + geom_point() |
183 | | -#' |
184 | | -#' plot + coord_trans(x = "log10") |
185 | | -#' plot + coord_trans(x = "sqrt") |
186 | | -#' } |
187 | | -coord_trans <- function(x = "identity", y = "identity", xlim = NULL, ylim = NULL, |
188 | | - limx = deprecated(), limy = deprecated(), clip = "on", expand = TRUE) { |
| 111 | +coord_trans <- function(...) { |
189 | 112 | deprecate_soft0( |
190 | 113 | "3.5.2", |
191 | 114 | "coord_trans()", |
192 | 115 | "coord_transform()" |
193 | 116 | ) |
194 | | - |
195 | | - coord_transform( |
196 | | - x = x, y = y, xlim = xlim, ylim = ylim, |
197 | | - limx = limx, limy = limy, clip = clip, expand = expand |
198 | | - ) |
| 117 | + coord_transform(...) |
199 | 118 | } |
200 | 119 |
|
201 | 120 | #' @rdname ggplot2-ggproto |
|
0 commit comments