Skip to content

Commit 7571122

Browse files
authored
increase dig.lab until breeaks are unique (#4888)
1 parent e2d704e commit 7571122

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# ggplot2 (development version)
22

3+
* Fix a bug in `stat_contour_filled()` where break value differences below a
4+
certain number of digits would cause the computations to fail (@thomasp85,
5+
#4874)
6+
37
* `stage()` now properly refers to the values without scale transformations for
48
the stage of `after_stat`. If your code requires the scaled version of the
59
values for some reason, you have to apply the same transformation by yourself,

R/stat-contour.r

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,17 @@ iso_to_polygon <- function(iso, group = 1) {
328328
#' @noRd
329329
#'
330330
pretty_isoband_levels <- function(isoband_levels, dig.lab = 3) {
331-
interval_low <- gsub(":.*$", "", isoband_levels)
332-
interval_high <- gsub("^[^:]*:", "", isoband_levels)
331+
interval_low <- as.numeric(gsub(":.*$", "", isoband_levels))
332+
interval_high <- as.numeric(gsub("^[^:]*:", "", isoband_levels))
333333

334-
label_low <- format(as.numeric(interval_low), digits = dig.lab, trim = TRUE)
335-
label_high <- format(as.numeric(interval_high), digits = dig.lab, trim = TRUE)
334+
breaks <- unique(c(interval_low, interval_high))
335+
336+
while(anyDuplicated(format(breaks, digits = dig.lab, trim = TRUE))) {
337+
dig.lab <- dig.lab + 1
338+
}
339+
340+
label_low <- format(interval_low, digits = dig.lab, trim = TRUE)
341+
label_high <- format(interval_high, digits = dig.lab, trim = TRUE)
336342

337343
# from the isoband::isobands() docs:
338344
# the intervals specifying isobands are closed at their lower boundary

0 commit comments

Comments
 (0)