Skip to content

stat_bin2d: doesn't handle integer-valued data #1147

Closed
@tgs

Description

@tgs

When I make a stat_bin2d using integer data, I still get the "range / 30" bin width.

> df <- data.frame(x = 0:3, y = 0:3)
> str(df)
'data.frame':   4 obs. of  2 variables:
 $ x: int  0 1 2 3
 $ y: int  0 1 2 3
> g <- ggplot(df, aes(x, y))
> g + stat_bin2d()

default stat_bin2d

However, in stat-bin2d.r, it looks like it is trying to handle integer data specially, to end up with something like this:

> g + stat_bin2d(binwidth=c(1,1), origin=c(-0.5,-0.5))

explicit stat_bin2d

Maybe, at some point, data$x retained its R integer type, but now something switches it to just numeric, and so the is.integer tests fail?

Here's a failing test case:

df <- data.frame(x = 0:3, y = 0:3)
g <- ggplot(df, aes(x, y))
p <- ggplot_build(g + stat_bin2d())

want_xbin <- cut(df$x, seq(-0.5, 4, 1))
expect_equal(p$data[[1]]$xbin, want_xbin)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions