diff --git a/NEWS.md b/NEWS.md index 97c111e8a0..840964dbe2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,9 @@ # ggplot2 (development version) +* When passing a function to `stat_contour(breaks)`, that function is used to + calculate the breaks even if `bins` and `binwidth` are missing + (@teunbrand, #5686). * `geom_step()` now supports `lineend`, `linejoin` and `linemitre` parameters (@teunbrand, #5705). * Fixed performance loss when the `.data` pronoun is used in `aes()` (#5730). diff --git a/R/stat-contour.R b/R/stat-contour.R index 9c08b639cf..882879430d 100644 --- a/R/stat-contour.R +++ b/R/stat-contour.R @@ -172,10 +172,8 @@ contour_breaks <- function(z_range, bins = NULL, binwidth = NULL, breaks = NULL) breaks_fun <- fullseq if (is.function(breaks)) { breaks_fun <- breaks - } - - # If no parameters set, use pretty bins - if (is.null(bins) && is.null(binwidth)) { + } else if (is.null(bins) && is.null(binwidth)) { + # If no parameters set, use pretty bins breaks <- pretty(z_range, 10) return(breaks) } @@ -206,7 +204,7 @@ contour_breaks <- function(z_range, bins = NULL, binwidth = NULL, breaks = NULL) } # if we haven't returned yet, compute breaks from binwidth - breaks_fun(z_range, binwidth) + breaks_fun(z_range, binwidth %||% (diff(z_range) / 10)) } #' Compute isoband objects