diff --git a/NEWS.md b/NEWS.md index a8c8dd0867..8ea91ab3b8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # ggplot2 (development version) +* The default `se` parameter in layers with `geom = "smooth"` will be `TRUE` + when the data has `ymin` and `ymax` parameters and `FALSE` if these are + absent. Note that this does not affect the default of `geom_smooth()` or + `stat_smooth()` (@teunbrand, #5572). * The bounded density option in `stat_density()` uses a wider range to prevent discontinuities (#5641). * `geom_raster()` now falls back to rendering as `geom_rect()` when coordinates diff --git a/R/geom-smooth.R b/R/geom-smooth.R index 535b8965a8..0c3432620c 100644 --- a/R/geom-smooth.R +++ b/R/geom-smooth.R @@ -125,6 +125,13 @@ geom_smooth <- function(mapping = NULL, data = NULL, GeomSmooth <- ggproto("GeomSmooth", Geom, setup_params = function(data, params) { params$flipped_aes <- has_flipped_aes(data, params, range_is_orthogonal = TRUE, ambiguous = TRUE) + params$se <- params$se %||% + if (params$flipped_aes) { + all(c("xmin", "xmax") %in% names(data)) + } else { + all(c("ymin", "ymax") %in% names(data)) + } + params },