Skip to content

Commit d05f8a4

Browse files
authored
Contour breaks function works in absence of bins and binwidth (#5703)
* prioritise `breaks = function(){}` * add news bullet
1 parent 50b3515 commit d05f8a4

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11

22
# ggplot2 (development version)
33

4+
* When passing a function to `stat_contour(breaks)`, that function is used to
5+
calculate the breaks even if `bins` and `binwidth` are missing
6+
(@teunbrand, #5686).
47
* `geom_step()` now supports `lineend`, `linejoin` and `linemitre` parameters
58
(@teunbrand, #5705).
69
* Fixed performance loss when the `.data` pronoun is used in `aes()` (#5730).

R/stat-contour.R

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,8 @@ contour_breaks <- function(z_range, bins = NULL, binwidth = NULL, breaks = NULL)
172172
breaks_fun <- fullseq
173173
if (is.function(breaks)) {
174174
breaks_fun <- breaks
175-
}
176-
177-
# If no parameters set, use pretty bins
178-
if (is.null(bins) && is.null(binwidth)) {
175+
} else if (is.null(bins) && is.null(binwidth)) {
176+
# If no parameters set, use pretty bins
179177
breaks <- pretty(z_range, 10)
180178
return(breaks)
181179
}
@@ -206,7 +204,7 @@ contour_breaks <- function(z_range, bins = NULL, binwidth = NULL, breaks = NULL)
206204
}
207205

208206
# if we haven't returned yet, compute breaks from binwidth
209-
breaks_fun(z_range, binwidth)
207+
breaks_fun(z_range, binwidth %||% (diff(z_range) / 10))
210208
}
211209

212210
#' Compute isoband objects

0 commit comments

Comments
 (0)