Skip to content

geom_bin_2d() should recognise 0-width data #6207

Closed
@teunbrand

Description

@teunbrand

In the example below, the computation goes wrong because in the y-direction we don't have any width.

library(ggplot2)
df <- data.frame(x = 1:5, y = 1)

ggplot(df, aes(x, y)) +
  geom_bin_2d()
#> Warning: Computation failed in `stat_bin2d()`.
#> Caused by error in `bin2d_breaks()` at ggplot2/R/stat-bin2d.R:64:5:
#> ! `origin` must be a number, not `NaN`.

Created on 2024-11-27 with reprex v2.1.1

I think the reasonable thing to do in such a case is to choose 1 bin for the y-direction with 1 width.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions