Skip to content
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

Only use finite breaks for computing fuzz #5668

Merged
merged 7 commits into from
Feb 27, 2024

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #5665.

Briefly, when histogram breaks are short and contain non-finite values, the median difference between breaks can become Inf.
In this PR, we only use finite breaks to compute the median difference for the fuzz-factor.

Reprex from #5665

devtools::load_all("~/packages/ggplot2")
#> ℹ Loading ggplot2

data <- data.frame(x = c(rep(1, 10), 5))

ggplot(data, aes(x)) +
  geom_histogram(
    breaks = c(-Inf, 2, 6, Inf),
    closed = "left"
  )
#> Warning: Removed 2 rows containing missing values or values outside the scale range
#> (`geom_bar()`).

Created on 2024-01-30 with reprex v2.1.0

R/bin.R Outdated
check_numeric(breaks)
fuzz <- fuzz %||% 1e-08 * stats::median(diff(breaks[is.finite(breaks)]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if there is only one finite break?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, it throws an error. I guess a not unreasonable approach would be to set the fuzz to a very small number?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I'd be fine with that, but we should not throw error at least

Copy link
Member

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@teunbrand teunbrand merged commit bc3e401 into tidyverse:main Feb 27, 2024
12 checks passed
@teunbrand teunbrand deleted the finite_fuzz branch February 27, 2024 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Histogram with breaks that uses Inf does not works
2 participants