diff --git a/NEWS.md b/NEWS.md index de3e87cee3..877e7e20be 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # ggplot2 (development version) +* `continuous_scale()` passes sorted limits to scale (@teunbrand, #5918) * The `arrow.fill` parameter is now applied to more line-based functions: `geom_path()`, `geom_line()`, `geom_step()` `geom_function()`, line geometries in `geom_sf()` and `element_line()`. diff --git a/R/scale-.R b/R/scale-.R index 9eaa153590..e5a924c4fa 100644 --- a/R/scale-.R +++ b/R/scale-.R @@ -127,11 +127,6 @@ continuous_scale <- function(aesthetics, scale_name = deprecated(), palette, nam guide <- "none" } - transform <- as.transform(transform) - if (!is.null(limits) && !is.function(limits)) { - limits <- transform$transform(limits) - } - # Convert formula to function if appropriate limits <- allow_lambda(limits) breaks <- allow_lambda(breaks) @@ -140,6 +135,14 @@ continuous_scale <- function(aesthetics, scale_name = deprecated(), palette, nam oob <- allow_lambda(oob) minor_breaks <- allow_lambda(minor_breaks) + transform <- as.transform(transform) + if (!is.null(limits) && !is.function(limits)) { + limits <- transform$transform(limits) + if (!anyNA(limits)) { + limits <- sort(limits) + } + } + ggproto(NULL, super, call = call, diff --git a/R/scale-view.R b/R/scale-view.R index de78ebffb6..9679001868 100644 --- a/R/scale-view.R +++ b/R/scale-view.R @@ -35,7 +35,7 @@ view_scale_primary <- function(scale, limits = scale$get_limits(), name = scale$name, scale_is_discrete = scale$is_discrete(), limits = limits, - continuous_range = continuous_range, + continuous_range = continuous_scale_sorted, breaks = breaks, minor_breaks = minor_breaks )