From c59de3974b7a11d4b22e70c1604ae8981c25ebad Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Fri, 23 Feb 2024 09:14:05 +0100 Subject: [PATCH 1/2] prioritise `breaks = function(){}` --- R/stat-contour.R | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) 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 From 7f13f47aee3efd3e084a141c1ef2f3f60ef63219 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Fri, 23 Feb 2024 11:32:44 +0100 Subject: [PATCH 2/2] add news bullet --- NEWS.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS.md b/NEWS.md index e6f6dca449..8ee23e0d6f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +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). + # ggplot2 3.5.0 This is a minor release that turned out quite beefy. It is focused on