Skip to content

Check if transformed limits in binning scales are valid before assigning them #4676

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
Nov 24, 2021
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
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# ggplot2 (development version)

* Binning scales are now more resilient to calculated limits that ends up being
`NaN` after transformations (@thomasp85, #4510)

* Strip padding in `facet_grid()` is now only in effect if `strip.placement = "outside"`
_and_ an axis is present between the strip and the panel (@thomasp85, #4610)

Expand Down
5 changes: 3 additions & 2 deletions R/scale-.r
Original file line number Diff line number Diff line change
Expand Up @@ -1083,11 +1083,12 @@ ScaleBinned <- ggproto("ScaleBinned", Scale,
new_limits[1] <- breaks[1]
breaks <- breaks[-1]
}
limits <- new_limits
} else {
bin_size <- max(breaks[1] - limits[1], limits[2] - breaks[1])
limits <- c(breaks[1] - bin_size, breaks[1] + bin_size)
new_limits <- c(breaks[1] - bin_size, breaks[1] + bin_size)
}
new_limits_trans <- suppressWarnings(self$trans$transform(new_limits))
limits[is.finite(new_limits_trans)] <- new_limits[is.finite(new_limits_trans)]
self$limits <- self$trans$transform(limits)
}
} else if (is.function(self$breaks)) {
Expand Down