Skip to content

increase dig.lab until breeaks are unique #4888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# ggplot2 (development version)

* Fix a bug in `stat_contour_filled()` where break value differences below a
certain number of digits would cause the computations to fail (@thomasp85,
#4874)

* `stage()` now properly refers to the values without scale transformations for
the stage of `after_stat`. If your code requires the scaled version of the
values for some reason, you have to apply the same transformation by yourself,
Expand Down
14 changes: 10 additions & 4 deletions R/stat-contour.r
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,17 @@ iso_to_polygon <- function(iso, group = 1) {
#' @noRd
#'
pretty_isoband_levels <- function(isoband_levels, dig.lab = 3) {
interval_low <- gsub(":.*$", "", isoband_levels)
interval_high <- gsub("^[^:]*:", "", isoband_levels)
interval_low <- as.numeric(gsub(":.*$", "", isoband_levels))
interval_high <- as.numeric(gsub("^[^:]*:", "", isoband_levels))

label_low <- format(as.numeric(interval_low), digits = dig.lab, trim = TRUE)
label_high <- format(as.numeric(interval_high), digits = dig.lab, trim = TRUE)
breaks <- unique(c(interval_low, interval_high))

while(anyDuplicated(format(breaks, digits = dig.lab, trim = TRUE))) {
dig.lab <- dig.lab + 1
}

label_low <- format(interval_low, digits = dig.lab, trim = TRUE)
label_high <- format(interval_high, digits = dig.lab, trim = TRUE)

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