diff --git a/NAMESPACE b/NAMESPACE index e7e47740d3..2b77d638c8 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -168,6 +168,7 @@ export(CoordQuickmap) export(CoordRadial) export(CoordSf) export(CoordTrans) +export(CoordTransform) export(Facet) export(FacetGrid) export(FacetNull) @@ -322,6 +323,7 @@ export(coord_quickmap) export(coord_radial) export(coord_sf) export(coord_trans) +export(coord_transform) export(cut_interval) export(cut_number) export(cut_width) diff --git a/NEWS.md b/NEWS.md index 272f551ca3..db37a62bc1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -280,6 +280,7 @@ (@teunbrand, #5938, #4327). * Fixed bug where empty discrete scales weren't recognised as such (@teunbrand, #5945). +* `coord_trans()` renamed to `coord_transform()` (@nmercadeb, #5825). * (internal) The summary function of `stat_summary()` and `stat_summary_bin()` is setup once in total instead of once per group (@teunbrand, #5971) * `facet_grid(space = "free")` can now be combined with `coord_fixed()` diff --git a/R/annotation-logticks.R b/R/annotation-logticks.R index 600bd6ce7c..ad8e023e18 100644 --- a/R/annotation-logticks.R +++ b/R/annotation-logticks.R @@ -24,7 +24,7 @@ #' @param scaled is the data already log-scaled? This should be `TRUE` #' (default) when the data is already transformed with `log10()` or when #' using `scale_y_log10()`. It should be `FALSE` when using -#' `coord_trans(y = "log10")`. +#' `coord_transform(y = "log10")`. #' @param colour Colour of the tick marks. #' @param linewidth Thickness of tick marks, in mm. #' @param linetype Linetype of tick marks (`solid`, `dashed`, etc.) @@ -36,7 +36,7 @@ #' @export #' @seealso [scale_y_continuous()], [scale_y_log10()] for log scale #' transformations. -#' @seealso [coord_trans()] for log coordinate transformations. +#' @seealso [coord_transform()] for log coordinate transformations. #' #' @examples #' # Make a log-log plot (without log ticks) @@ -75,7 +75,7 @@ #' # Using a coordinate transform requires scaled = FALSE #' t <- ggplot(msleep, aes(bodywt, brainwt)) + #' geom_point() + -#' coord_trans(x = "log10", y = "log10") + +#' coord_transform(x = "log10", y = "log10") + #' theme_bw() #' t + annotation_logticks(scaled = FALSE) #' diff --git a/R/coord-.R b/R/coord-.R index 2b560292c4..a948b042ac 100644 --- a/R/coord-.R +++ b/R/coord-.R @@ -1,6 +1,6 @@ #' @section Coordinate systems: #' -#' All `coord_*()` functions (like `coord_trans()`) return a `Coord*` +#' All `coord_*()` functions (like `coord_transform()`) return a `Coord*` #' object (like `CoordTrans`). #' #' Each of the `Coord*` objects is a [ggproto()] object, @@ -16,7 +16,7 @@ #' - `backtransform_range(panel_params)`: Extracts the panel range provided #' in `panel_params` (created by `setup_panel_params()`, see below) and #' back-transforms to data coordinates. This back-transformation can be needed -#' for coords such as `coord_trans()` where the range in the transformed +#' for coords such as `coord_transform()` where the range in the transformed #' coordinates differs from the range in the untransformed coordinates. Returns #' a list of two ranges, `x` and `y`, and these correspond to the variables #' mapped to the `x` and `y` aesthetics, even for coords such as `coord_flip()` diff --git a/R/coord-transform.R b/R/coord-transform.R index 18230a1742..2b426b90e3 100644 --- a/R/coord-transform.R +++ b/R/coord-transform.R @@ -1,6 +1,6 @@ #' Transformed Cartesian coordinate system #' -#' `coord_trans()` is different to scale transformations in that it occurs after +#' `coord_transform()` is different to scale transformations in that it occurs after #' statistical transformation and will affect the visual appearance of geoms - there is #' no guarantee that straight lines will continue to be straight. #' @@ -8,9 +8,12 @@ #' [scales::new_transform()] for list of transformations, and instructions #' on how to create your own. #' +#' The `coord_trans()` function is deprecated in favour of `coord_transform()`. +#' #' @inheritParams coord_cartesian #' @param x,y Transformers for x and y axes or their names. #' @param limx,limy `r lifecycle::badge("deprecated")` use `xlim` and `ylim` instead. +#' @param ... Arguments forwarded to `coord_transform()`. #' @seealso #' The `r link_book("coord transformations section", "coord#transformations-with-coord_trans")` #' @export @@ -30,7 +33,7 @@ #' # * by transforming the coordinate system: #' ggplot(diamonds, aes(carat, price)) + #' geom_point() + -#' coord_trans(x = "log10", y = "log10") +#' coord_transform(x = "log10", y = "log10") #' #' # The difference between transforming the scales and #' # transforming the coordinate system is that scale @@ -49,7 +52,7 @@ #' ggplot(d, aes(carat, price)) + #' geom_point() + #' geom_smooth(method = "lm") + -#' coord_trans(x = "log10", y = "log10") +#' coord_transform(x = "log10", y = "log10") #' #' # Here I used a subset of diamonds so that the smoothed line didn't #' # drop below zero, which obviously causes problems on the log-transformed @@ -62,7 +65,7 @@ #' geom_smooth(method = "lm") + #' scale_x_log10() + #' scale_y_log10() + -#' coord_trans(x = scales::transform_exp(10), y = scales::transform_exp(10)) +#' coord_transform(x = scales::transform_exp(10), y = scales::transform_exp(10)) #' #' # cf. #' ggplot(diamonds, aes(carat, price)) + @@ -74,18 +77,18 @@ #' df <- data.frame(a = abs(rnorm(26)),letters) #' plot <- ggplot(df,aes(a,letters)) + geom_point() #' -#' plot + coord_trans(x = "log10") -#' plot + coord_trans(x = "sqrt") +#' plot + coord_transform(x = "log10") +#' plot + coord_transform(x = "sqrt") #' } -coord_trans <- function(x = "identity", y = "identity", xlim = NULL, ylim = NULL, - limx = deprecated(), limy = deprecated(), clip = "on", - expand = TRUE, reverse = "none") { +coord_transform <- function(x = "identity", y = "identity", xlim = NULL, ylim = NULL, + limx = deprecated(), limy = deprecated(), clip = "on", + expand = TRUE, reverse = "none") { if (lifecycle::is_present(limx)) { - deprecate_warn0("3.3.0", "coord_trans(limx)", "coord_trans(xlim)") + deprecate_warn0("3.3.0", "coord_transform(limx)", "coord_transform(xlim)") xlim <- limx } if (lifecycle::is_present(limy)) { - deprecate_warn0("3.3.0", "coord_trans(limy)", "coord_trans(ylim)") + deprecate_warn0("3.3.0", "coord_transform(limy)", "coord_transform(ylim)") ylim <- limy } @@ -96,7 +99,8 @@ coord_trans <- function(x = "identity", y = "identity", xlim = NULL, ylim = NULL if (is.character(x)) x <- as.transform(x) if (is.character(y)) y <- as.transform(y) - ggproto(NULL, CoordTrans, + ggproto( + NULL, CoordTransform, trans = list(x = x, y = y), limits = list(x = xlim, y = ylim), expand = expand, @@ -105,12 +109,23 @@ coord_trans <- function(x = "identity", y = "identity", xlim = NULL, ylim = NULL ) } +#' @rdname coord_transform +#' @export +coord_trans <- function(...) { + deprecate_soft0( + "3.5.2", + "coord_trans()", + "coord_transform()" + ) + coord_transform(...) +} #' @rdname ggplot2-ggproto #' @format NULL #' @usage NULL #' @export -CoordTrans <- ggproto("CoordTrans", Coord, +CoordTransform <- ggproto( + "CoordTransform", Coord, is_free = function() TRUE, distance = function(self, x, y, panel_params) { max_dist <- dist_euclidean(panel_params$x.range, panel_params$y.range) @@ -182,6 +197,13 @@ CoordTrans <- ggproto("CoordTrans", Coord, } ) +# TODO: deprecate this some time in the future +#' @rdname ggplot2-ggproto +#' @format NULL +#' @usage NULL +#' @export +CoordTrans <- ggproto("CoordTrans", CoordTransform) + transform_value <- function(trans, value, range) { if (is.null(value)) return(value) @@ -257,3 +279,4 @@ warn_new_infinites <- function(old_values, new_values, axis, call = caller_env() cli::cli_warn("Transformation introduced infinite values in {axis}-axis", call = call) } } + diff --git a/R/geom-histogram.R b/R/geom-histogram.R index 7bd832b611..e7dcc12713 100644 --- a/R/geom-histogram.R +++ b/R/geom-histogram.R @@ -113,11 +113,11 @@ #' # no observations have 0 ratings. #' m + #' geom_histogram(boundary = 0) + -#' coord_trans(x = "log10") +#' coord_transform(x = "log10") #' # Use boundary = 0, to make sure we don't take sqrt of negative values #' m + #' geom_histogram(boundary = 0) + -#' coord_trans(x = "sqrt") +#' coord_transform(x = "sqrt") #' #' # You can also transform the y axis. Remember that the base of the bars #' # has value 0, so log transformations are not appropriate diff --git a/R/geom-violin.R b/R/geom-violin.R index 24d8fd07d9..07c6b56907 100644 --- a/R/geom-violin.R +++ b/R/geom-violin.R @@ -79,10 +79,10 @@ #' scale_y_log10() #' m + #' geom_violin() + -#' coord_trans(y = "log10") +#' coord_transform(y = "log10") #' m + #' geom_violin() + -#' scale_y_log10() + coord_trans(y = "log10") +#' scale_y_log10() + coord_transform(y = "log10") #' #' # Violin plots with continuous x: #' # Use the group aesthetic to group observations in violins diff --git a/R/guide-axis-logticks.R b/R/guide-axis-logticks.R index 37273cba06..fd610ebb2d 100644 --- a/R/guide-axis-logticks.R +++ b/R/guide-axis-logticks.R @@ -13,7 +13,7 @@ NULL #' @param prescale.base Base of logarithm used to transform data manually. The #' default, `NULL`, will use the scale transformation to calculate positions. #' Only set `prescale.base` if the data has already been log-transformed. -#' When using a log-transform in the position scale or in `coord_trans()`, +#' When using a log-transform in the position scale or in `coord_transform()`, #' keep the default `NULL` argument. #' @param negative.small When the scale limits include 0 or negative numbers, #' what should be the smallest absolute value that is marked with a tick? @@ -39,7 +39,7 @@ NULL #' scale_y_log10(guide = "axis_logticks") #' #' # Or with log-transformed coordinates -#' p + coord_trans(x = "log10", y = "log10") + +#' p + coord_transform(x = "log10", y = "log10") + #' guides(x = "axis_logticks", y = "axis_logticks") #' #' # When data is transformed manually, one should provide `prescale.base` diff --git a/R/stat-summary.R b/R/stat-summary.R index a32eda8ca0..5d08632031 100644 --- a/R/stat-summary.R +++ b/R/stat-summary.R @@ -123,7 +123,7 @@ #' # statistic has been computed. This means we're calculating the summary on the raw data #' # and stretching the geoms onto the log scale. Compare the widths of the #' # standard errors. -#' m2 + coord_trans(y="log10") +#' m2 + coord_transform(y="log10") #' } #' } stat_summary <- function(mapping = NULL, data = NULL, diff --git a/R/summarise-plot.R b/R/summarise-plot.R index 9ab046cb8c..64d16ca7b2 100644 --- a/R/summarise-plot.R +++ b/R/summarise-plot.R @@ -33,7 +33,7 @@ #' @section Coord summary: #' #' The function `summarise_coord()` returns information about the log base for -#' coordinates that are log-transformed in `coord_trans()`, and it also indicates +#' coordinates that are log-transformed in `coord_transform()`, and it also indicates #' whether the coord has flipped the x and y axes. #' #' @section Layer summary: diff --git a/_pkgdown.yml b/_pkgdown.yml index 5b0505afd8..a096c4f9a9 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -166,7 +166,7 @@ reference: The coordinate system determines how the `x` and `y` aesthetics combine to position elements in the plot. The default coordinate system is Cartesian (`coord_cartesian()`), which can be tweaked with `coord_map()`, - `coord_fixed()`, `coord_flip()`, and `coord_trans()`, or completely + `coord_fixed()`, `coord_flip()`, and `coord_transform()`, or completely replaced with `coord_polar()`. contents: - coord_cartesian @@ -174,6 +174,7 @@ reference: - coord_flip - coord_map - coord_polar + - coord_transform - coord_trans - title: Themes diff --git a/man/annotation_logticks.Rd b/man/annotation_logticks.Rd index 490a7d3b17..b37a54560d 100644 --- a/man/annotation_logticks.Rd +++ b/man/annotation_logticks.Rd @@ -35,7 +35,7 @@ of the plot area. Default is off (\code{FALSE}). You will also need to use \item{scaled}{is the data already log-scaled? This should be \code{TRUE} (default) when the data is already transformed with \code{log10()} or when using \code{scale_y_log10()}. It should be \code{FALSE} when using -\code{coord_trans(y = "log10")}.} +\code{coord_transform(y = "log10")}.} \item{short}{a \code{\link[grid:unit]{grid::unit()}} object specifying the length of the short tick marks} @@ -105,7 +105,7 @@ b + annotation_logticks() # Using a coordinate transform requires scaled = FALSE t <- ggplot(msleep, aes(bodywt, brainwt)) + geom_point() + - coord_trans(x = "log10", y = "log10") + + coord_transform(x = "log10", y = "log10") + theme_bw() t + annotation_logticks(scaled = FALSE) @@ -120,5 +120,5 @@ a + annotation_logticks( \code{\link[=scale_y_continuous]{scale_y_continuous()}}, \code{\link[=scale_y_log10]{scale_y_log10()}} for log scale transformations. -\code{\link[=coord_trans]{coord_trans()}} for log coordinate transformations. +\code{\link[=coord_transform]{coord_transform()}} for log coordinate transformations. } diff --git a/man/coord_trans.Rd b/man/coord_transform.Rd similarity index 87% rename from man/coord_trans.Rd rename to man/coord_transform.Rd index 0d9d2d6f79..851d7b2832 100644 --- a/man/coord_trans.Rd +++ b/man/coord_transform.Rd @@ -1,10 +1,11 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/coord-transform.R -\name{coord_trans} +\name{coord_transform} +\alias{coord_transform} \alias{coord_trans} \title{Transformed Cartesian coordinate system} \usage{ -coord_trans( +coord_transform( x = "identity", y = "identity", xlim = NULL, @@ -15,6 +16,8 @@ coord_trans( expand = TRUE, reverse = "none" ) + +coord_trans(...) } \arguments{ \item{x, y}{Transformers for x and y axes or their names.} @@ -44,9 +47,11 @@ vector to control a single direction, e.g. \code{expand = c(bottom = FALSE)}.} (default) keeps directions as is. \code{"x"} and \code{"y"} can be used to reverse their respective directions. \code{"xy"} can be used to reverse both directions.} + +\item{...}{Arguments forwarded to \code{coord_transform()}.} } \description{ -\code{coord_trans()} is different to scale transformations in that it occurs after +\code{coord_transform()} is different to scale transformations in that it occurs after statistical transformation and will affect the visual appearance of geoms - there is no guarantee that straight lines will continue to be straight. } @@ -54,6 +59,8 @@ no guarantee that straight lines will continue to be straight. Transformations only work with continuous values: see \code{\link[scales:new_transform]{scales::new_transform()}} for list of transformations, and instructions on how to create your own. + +The \code{coord_trans()} function is deprecated in favour of \code{coord_transform()}. } \examples{ \donttest{ @@ -71,7 +78,7 @@ ggplot(diamonds, aes(carat, price)) + # * by transforming the coordinate system: ggplot(diamonds, aes(carat, price)) + geom_point() + - coord_trans(x = "log10", y = "log10") + coord_transform(x = "log10", y = "log10") # The difference between transforming the scales and # transforming the coordinate system is that scale @@ -90,7 +97,7 @@ ggplot(d, aes(carat, price)) + ggplot(d, aes(carat, price)) + geom_point() + geom_smooth(method = "lm") + - coord_trans(x = "log10", y = "log10") + coord_transform(x = "log10", y = "log10") # Here I used a subset of diamonds so that the smoothed line didn't # drop below zero, which obviously causes problems on the log-transformed @@ -103,7 +110,7 @@ ggplot(diamonds, aes(carat, price)) + geom_smooth(method = "lm") + scale_x_log10() + scale_y_log10() + - coord_trans(x = scales::transform_exp(10), y = scales::transform_exp(10)) + coord_transform(x = scales::transform_exp(10), y = scales::transform_exp(10)) # cf. ggplot(diamonds, aes(carat, price)) + @@ -115,8 +122,8 @@ set.seed(1) df <- data.frame(a = abs(rnorm(26)),letters) plot <- ggplot(df,aes(a,letters)) + geom_point() -plot + coord_trans(x = "log10") -plot + coord_trans(x = "sqrt") +plot + coord_transform(x = "log10") +plot + coord_transform(x = "sqrt") } } \seealso{ diff --git a/man/geom_histogram.Rd b/man/geom_histogram.Rd index f0532d8b25..99c538fa72 100644 --- a/man/geom_histogram.Rd +++ b/man/geom_histogram.Rd @@ -312,11 +312,11 @@ m + # no observations have 0 ratings. m + geom_histogram(boundary = 0) + - coord_trans(x = "log10") + coord_transform(x = "log10") # Use boundary = 0, to make sure we don't take sqrt of negative values m + geom_histogram(boundary = 0) + - coord_trans(x = "sqrt") + coord_transform(x = "sqrt") # You can also transform the y axis. Remember that the base of the bars # has value 0, so log transformations are not appropriate diff --git a/man/geom_violin.Rd b/man/geom_violin.Rd index 590ebface6..d61dc29018 100644 --- a/man/geom_violin.Rd +++ b/man/geom_violin.Rd @@ -264,10 +264,10 @@ m + scale_y_log10() m + geom_violin() + - coord_trans(y = "log10") + coord_transform(y = "log10") m + geom_violin() + - scale_y_log10() + coord_trans(y = "log10") + scale_y_log10() + coord_transform(y = "log10") # Violin plots with continuous x: # Use the group aesthetic to group observations in violins diff --git a/man/ggplot2-ggproto.Rd b/man/ggplot2-ggproto.Rd index dcd57c12a1..a846e3005f 100644 --- a/man/ggplot2-ggproto.Rd +++ b/man/ggplot2-ggproto.Rd @@ -47,6 +47,7 @@ \alias{CoordPolar} \alias{CoordQuickmap} \alias{CoordRadial} +\alias{CoordTransform} \alias{CoordTrans} \alias{Facet} \alias{FacetGrid} @@ -216,7 +217,7 @@ See also the \href{https://ggplot2-book.org/extensions#sec-new-geoms}{new geoms \section{Coordinate systems}{ -All \verb{coord_*()} functions (like \code{coord_trans()}) return a \verb{Coord*} +All \verb{coord_*()} functions (like \code{coord_transform()}) return a \verb{Coord*} object (like \code{CoordTrans}). Each of the \verb{Coord*} objects is a \code{\link[=ggproto]{ggproto()}} object, @@ -232,7 +233,7 @@ object, you typically will want to implement one or more of the following: \item \code{backtransform_range(panel_params)}: Extracts the panel range provided in \code{panel_params} (created by \code{setup_panel_params()}, see below) and back-transforms to data coordinates. This back-transformation can be needed -for coords such as \code{coord_trans()} where the range in the transformed +for coords such as \code{coord_transform()} where the range in the transformed coordinates differs from the range in the untransformed coordinates. Returns a list of two ranges, \code{x} and \code{y}, and these correspond to the variables mapped to the \code{x} and \code{y} aesthetics, even for coords such as \code{coord_flip()} @@ -324,7 +325,7 @@ return an empty grob for each panel. \item \code{draw_front}: As above except the returned grob is placed between the layer stack and the foreground defined by the Coord object (usually empty). The default is, as above, to return an empty grob. -\item \code{draw_facet_panels}: Draws each panel for the facet. Should return a list +\item \code{draw_panel_content}: Draws each panel for the facet. Should return a list of grobs, one for each panel. The output is used by the \code{draw_panels} method. \item \code{draw_labels}: Given the gtable returned by \code{draw_panels}, diff --git a/man/guide_axis_logticks.Rd b/man/guide_axis_logticks.Rd index 7398f24890..922e354566 100644 --- a/man/guide_axis_logticks.Rd +++ b/man/guide_axis_logticks.Rd @@ -29,7 +29,7 @@ values of the \code{axis.ticks.length} theme setting.} \item{prescale.base}{Base of logarithm used to transform data manually. The default, \code{NULL}, will use the scale transformation to calculate positions. Only set \code{prescale.base} if the data has already been log-transformed. -When using a log-transform in the position scale or in \code{coord_trans()}, +When using a log-transform in the position scale or in \code{coord_transform()}, keep the default \code{NULL} argument.} \item{negative.small}{When the scale limits include 0 or negative numbers, @@ -97,7 +97,7 @@ p + scale_x_log10(guide = "axis_logticks") + scale_y_log10(guide = "axis_logticks") # Or with log-transformed coordinates -p + coord_trans(x = "log10", y = "log10") + +p + coord_transform(x = "log10", y = "log10") + guides(x = "axis_logticks", y = "axis_logticks") # When data is transformed manually, one should provide `prescale.base` diff --git a/man/stat_summary.Rd b/man/stat_summary.Rd index 20326b840f..317af4481c 100644 --- a/man/stat_summary.Rd +++ b/man/stat_summary.Rd @@ -299,7 +299,7 @@ m2 + scale_y_log10() # statistic has been computed. This means we're calculating the summary on the raw data # and stretching the geoms onto the log scale. Compare the widths of the # standard errors. -m2 + coord_trans(y="log10") +m2 + coord_transform(y="log10") } } } diff --git a/man/summarise_plot.Rd b/man/summarise_plot.Rd index 6be6635876..39ba6fb7d4 100644 --- a/man/summarise_plot.Rd +++ b/man/summarise_plot.Rd @@ -54,7 +54,7 @@ returned by \code{summarise_plot()}. The function \code{summarise_coord()} returns information about the log base for -coordinates that are log-transformed in \code{coord_trans()}, and it also indicates +coordinates that are log-transformed in \code{coord_transform()}, and it also indicates whether the coord has flipped the x and y axes. } diff --git a/tests/testthat/_snaps/coord-transform.md b/tests/testthat/_snaps/coord-transform.md index cec8af5ae2..ee135f78d9 100644 --- a/tests/testthat/_snaps/coord-transform.md +++ b/tests/testthat/_snaps/coord-transform.md @@ -1,4 +1,4 @@ -# warnings are generated when coord_trans() results in new infinite values +# warnings are generated when coord_transform() results in new infinite values Transformation introduced infinite values in y-axis @@ -6,7 +6,7 @@ Transformation introduced infinite values in x-axis -# coord_trans() throws error when limits are badly specified +# coord_transform() throws error when limits are badly specified `xlim` must be a vector, not a object. diff --git a/tests/testthat/_snaps/coord-transform/basic-coord-trans-plot.svg b/tests/testthat/_snaps/coord-transform/basic-coord-transform-plot.svg similarity index 99% rename from tests/testthat/_snaps/coord-transform/basic-coord-trans-plot.svg rename to tests/testthat/_snaps/coord-transform/basic-coord-transform-plot.svg index 6e150c767f..7d103a7626 100644 --- a/tests/testthat/_snaps/coord-transform/basic-coord-trans-plot.svg +++ b/tests/testthat/_snaps/coord-transform/basic-coord-transform-plot.svg @@ -286,6 +286,6 @@ suv class hwy -basic coord_trans() plot +basic coord_transform() plot diff --git a/tests/testthat/_snaps/coord-transform/sec-axis-with-coord-trans.svg b/tests/testthat/_snaps/coord-transform/sec-axis-with-coord-transform.svg similarity index 99% rename from tests/testthat/_snaps/coord-transform/sec-axis-with-coord-trans.svg rename to tests/testthat/_snaps/coord-transform/sec-axis-with-coord-transform.svg index 9a94eed9ae..34582434c9 100644 --- a/tests/testthat/_snaps/coord-transform/sec-axis-with-coord-trans.svg +++ b/tests/testthat/_snaps/coord-transform/sec-axis-with-coord-transform.svg @@ -312,6 +312,6 @@ cty hwy log2(hwy) -sec_axis with coord_trans() +sec_axis with coord_transform() diff --git a/tests/testthat/_snaps/guide-axis/guide-titles-with-coord-trans.svg b/tests/testthat/_snaps/guide-axis/guide-titles-with-coord-transform.svg similarity index 98% rename from tests/testthat/_snaps/guide-axis/guide-titles-with-coord-trans.svg rename to tests/testthat/_snaps/guide-axis/guide-titles-with-coord-transform.svg index 4a658436f4..18419ddec9 100644 --- a/tests/testthat/_snaps/guide-axis/guide-titles-with-coord-trans.svg +++ b/tests/testthat/_snaps/guide-axis/guide-titles-with-coord-transform.svg @@ -75,6 +75,6 @@ x (primary) y (primary) y (secondary) -guide titles with coord_trans() +guide titles with coord_transform() diff --git a/tests/testthat/test-coord-train.R b/tests/testthat/test-coord-train.R index 9d42ec3c79..39344d8e2d 100644 --- a/tests/testthat/test-coord-train.R +++ b/tests/testthat/test-coord-train.R @@ -25,7 +25,7 @@ test_that("NA's don't appear in breaks", { # Check the various types of coords to make sure they don't have NA breaks expect_false(any_NA_major_minor(coord_polar()$setup_panel_params(scale_x, scale_y))) expect_false(any_NA_major_minor(coord_cartesian()$setup_panel_params(scale_x, scale_y))) - expect_false(any_NA_major_minor(coord_trans()$setup_panel_params(scale_x, scale_y))) + expect_false(any_NA_major_minor(coord_transform()$setup_panel_params(scale_x, scale_y))) expect_false(any_NA_major_minor(coord_fixed()$setup_panel_params(scale_x, scale_y))) skip_if_not_installed("mapproj") diff --git a/tests/testthat/test-coord-transform.R b/tests/testthat/test-coord-transform.R index 7621f5ed9c..70b5c51b36 100644 --- a/tests/testthat/test-coord-transform.R +++ b/tests/testthat/test-coord-transform.R @@ -1,11 +1,11 @@ -test_that("warnings are generated when coord_trans() results in new infinite values", { +test_that("warnings are generated when coord_transform() results in new infinite values", { p <- ggplot(head(diamonds, 20)) + geom_bar(aes(x = cut)) + - coord_trans(y = "log10") + coord_transform(y = "log10") p2 <- ggplot(data_frame(a = c(1, 2, 0), b = c(10, 6, 4)), aes(a, b)) + geom_point() + - coord_trans(x = "log") + coord_transform(x = "log") # TODO: These multiple warnings should be summarized nicely. Until this gets # fixed, this test ignores all the following errors than the first one. @@ -18,15 +18,15 @@ test_that("warnings are generated when coord_trans() results in new infinite val test_that("no warnings are generated when original data has Inf values, but no new Inf values created from the transformation", { p <- ggplot(data_frame(x = c(-Inf, 2, 0), y = c(Inf, 6, 4)), aes(x, y)) + geom_point() + - coord_trans(x = 'identity') + coord_transform(x = 'identity') expect_silent(benchplot(p)) }) -test_that("coord_trans() expands axes identically to coord_cartesian()", { +test_that("coord_transform() expands axes identically to coord_cartesian()", { p <- ggplot(mpg, aes(class, hwy)) + geom_point() built_cartesian <- ggplot_build(p + coord_cartesian()) - built_trans <- ggplot_build(p + coord_trans()) + built_trans <- ggplot_build(p + coord_transform()) cartesian_params <- built_cartesian$layout$panel_params[[1]] trans_params <- built_trans$layout$panel_params[[1]] @@ -35,10 +35,10 @@ test_that("coord_trans() expands axes identically to coord_cartesian()", { expect_identical(cartesian_params$y.range, trans_params$y.range) }) -test_that("coord_trans(expand = FALSE) expands axes identically to coord_cartesian(expand = FALSE)", { +test_that("coord_transform(expand = FALSE) expands axes identically to coord_cartesian(expand = FALSE)", { p <- ggplot(mpg, aes(class, hwy)) + geom_point() built_cartesian <- ggplot_build(p + coord_cartesian(expand = FALSE)) - built_trans <- ggplot_build(p + coord_trans(expand = FALSE)) + built_trans <- ggplot_build(p + coord_transform(expand = FALSE)) cartesian_params <- built_cartesian$layout$panel_params[[1]] trans_params <- built_trans$layout$panel_params[[1]] @@ -47,10 +47,10 @@ test_that("coord_trans(expand = FALSE) expands axes identically to coord_cartesi expect_identical(cartesian_params$y.range, trans_params$y.range) }) -test_that("coord_trans(y = 'log10') expands the x axis identically to scale_y_log10()", { +test_that("coord_transform(y = 'log10') expands the x axis identically to scale_y_log10()", { p <- ggplot(mpg, aes(class, hwy)) + geom_point() built_cartesian <- ggplot_build(p + scale_y_log10()) - built_trans <- ggplot_build(p + coord_trans(y = "log10")) + built_trans <- ggplot_build(p + coord_transform(y = "log10")) cartesian_params <- built_cartesian$layout$panel_params[[1]] trans_params <- built_trans$layout$panel_params[[1]] @@ -58,12 +58,12 @@ test_that("coord_trans(y = 'log10') expands the x axis identically to scale_y_lo expect_identical(cartesian_params$y.range, trans_params$y.range) }) -test_that("coord_trans() expands axes outside the domain of the axis trans", { +test_that("coord_transform() expands axes outside the domain of the axis trans", { # transform_sqrt() has a lower limit of 0 df <- data_frame(x = 1, y = c(0, 1, 2)) p <- ggplot(df, aes(x, y)) + geom_point() built_cartesian <- ggplot_build(p + scale_y_sqrt()) - built_trans <- ggplot_build(p + coord_trans(y = "sqrt")) + built_trans <- ggplot_build(p + coord_transform(y = "sqrt")) cartesian_params <- built_cartesian$layout$panel_params[[1]] trans_params <- built_trans$layout$panel_params[[1]] @@ -71,12 +71,12 @@ test_that("coord_trans() expands axes outside the domain of the axis trans", { expect_identical(cartesian_params$y.range, trans_params$y.range) }) -test_that("coord_trans() works with the reverse transformation", { +test_that("coord_transform() works with the reverse transformation", { df <- data_frame(x = c("1-one", "2-two", "3-three"), y = c(20, 30, 40)) p <- ggplot(df, aes(x, y)) + geom_point() built_cartesian <- ggplot_build(p + scale_y_reverse()) - built_trans <- ggplot_build(p + coord_trans(y = "reverse")) + built_trans <- ggplot_build(p + coord_transform(y = "reverse")) cartesian_params <- built_cartesian$layout$panel_params[[1]] trans_params <- built_trans$layout$panel_params[[1]] @@ -84,12 +84,12 @@ test_that("coord_trans() works with the reverse transformation", { expect_identical(cartesian_params$y.range, trans_params$y.range) }) -test_that("coord_trans() can reverse discrete axes", { +test_that("coord_transform() can reverse discrete axes", { df <- data_frame(x = c("1-one", "2-two", "3-three"), y = c(20, 30, 40)) p <- ggplot(df, aes(x, y)) + geom_point() built_cartesian <- ggplot_build(p) - built_trans <- ggplot_build(p + coord_trans(x = "reverse")) + built_trans <- ggplot_build(p + coord_transform(x = "reverse")) cartesian_params <- built_cartesian$layout$panel_params[[1]] trans_params <- built_trans$layout$panel_params[[1]] @@ -97,18 +97,18 @@ test_that("coord_trans() can reverse discrete axes", { expect_identical(cartesian_params$x.range, -rev(trans_params$x.range)) }) -test_that("basic coord_trans() plot displays both continuous and discrete axes", { +test_that("basic coord_transform() plot displays both continuous and discrete axes", { expect_doppelganger( - "basic coord_trans() plot", + "basic coord_transform() plot", ggplot(mpg, aes(class, hwy)) + geom_point() + - coord_trans(y = "log10") + coord_transform(y = "log10") ) }) -test_that("second axes display in coord_trans()", { +test_that("second axes display in coord_transform()", { expect_doppelganger( - "sec_axis with coord_trans()", + "sec_axis with coord_transform()", ggplot(mpg, aes(cty, hwy)) + geom_point() + scale_y_continuous( @@ -120,23 +120,23 @@ test_that("second axes display in coord_trans()", { breaks = 2^c(3.5, 4, 4.5, 5, 5.5) ) + scale_x_continuous(sec.axis = dup_axis()) + - coord_trans(y = "log2") + coord_transform(y = "log2") ) }) -test_that("coord_trans() throws error when limits are badly specified", { +test_that("coord_transform() throws error when limits are badly specified", { # throws error when limit is a Scale object instead of vector - expect_snapshot_error(ggplot() + coord_trans(xlim=xlim(1,1))) + expect_snapshot_error(ggplot() + coord_transform(xlim=xlim(1,1))) # throws error when limit's length is different than two - expect_snapshot_error(ggplot() + coord_trans(ylim=1:3)) + expect_snapshot_error(ggplot() + coord_transform(ylim=1:3)) }) test_that("transformed coords can be reversed", { p <- ggplot(data_frame0(x = c(1, 100), y = c(1, 100))) + aes(x = x, y = y) + geom_point() + - coord_trans( + coord_transform( x = "log10", y = "log10", xlim = c(0.1, 1000), ylim = c(0.1, 1000), expand = FALSE, reverse = "xy" diff --git a/tests/testthat/test-geom-hex.R b/tests/testthat/test-geom-hex.R index 0934f8fd27..498f00d407 100644 --- a/tests/testthat/test-geom-hex.R +++ b/tests/testthat/test-geom-hex.R @@ -33,7 +33,7 @@ test_that("geom_hex works in non-linear coordinate systems", { p <- ggplot(mpg, aes(displ, hwy)) + geom_hex() expect_doppelganger("hex bin plot with sqrt-transformed y", - p + coord_trans(y = "sqrt") + p + coord_transform(y = "sqrt") ) expect_doppelganger("hex bin plot in polar coordinates", p + coord_polar() diff --git a/tests/testthat/test-guide-axis.R b/tests/testthat/test-guide-axis.R index 85e1477024..5342332e02 100644 --- a/tests/testthat/test-guide-axis.R +++ b/tests/testthat/test-guide-axis.R @@ -260,7 +260,7 @@ test_that("Axis titles won't be blown away by coord_*()", { y.sec = guide_axis(title = "y (secondary)") ) - expect_doppelganger("guide titles with coord_trans()", plot + coord_trans()) + expect_doppelganger("guide titles with coord_transform()", plot + coord_transform()) # TODO # expect_doppelganger("guide titles with coord_polar()", plot + coord_polar()) # TODO @@ -341,7 +341,7 @@ test_that("logticks look as they should", { scale_x_continuous( breaks = c(-100, -10, -1, 0, 1, 10, 100) ) + - coord_trans(x = transform_pseudo_log()) + + coord_transform(x = transform_pseudo_log()) + theme_test() + theme(axis.line = element_line(colour = "black"), panel.border = element_blank(), diff --git a/tests/testthat/test-plot-summary-api.R b/tests/testthat/test-plot-summary-api.R index 2b4704e94c..6d90f9f3ae 100644 --- a/tests/testthat/test-plot-summary-api.R +++ b/tests/testthat/test-plot-summary-api.R @@ -100,7 +100,7 @@ test_that("coord summary - basic", { test_that("coord summary - log transformations", { # Check for coord log transformations (should ignore log scale) - pl <- p + scale_x_log10() + coord_trans(x = "log2") + pl <- p + scale_x_log10() + coord_transform(x = "log2") ll <- summarise_coord(ggplot_build(pl)) expect_identical(ll, list(xlog = 2, ylog = NA_real_, flip = FALSE)) })