diff --git a/NEWS.md b/NEWS.md index 28ecb99196..f9bdc996e0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # ggplot2 (development version) +* Fixed bug in `stat_function()` so x-axis title now produced automatically + when no data added. (@phispu, #5647). * geom_sf now accepts shape names (@sierrajohnson, #5808) * Added `gg` class to `labs()` (@phispu, #5553). * Missing values from discrete palettes are no longer translated diff --git a/R/stat-function.R b/R/stat-function.R index 8f31b8daba..bf6d2e4b74 100644 --- a/R/stat-function.R +++ b/R/stat-function.R @@ -50,7 +50,7 @@ stat_function <- function(mapping = NULL, data = NULL, #' @usage NULL #' @export StatFunction <- ggproto("StatFunction", Stat, - default_aes = aes(y = after_scale(y)), + default_aes = aes(x = NULL, y = after_scale(y)), compute_group = function(data, scales, fun, xlim = NULL, n = 101, args = list()) { if (is.null(scales$x)) {