Skip to content

Allow functions in breaks argument to stat_bin() #4561

Closed
@aijordan

Description

@aijordan

Allowing breaks in stat_bin() to accept functions would be useful in the context of grouping structures.

The changes would also enable facet histograms for estimators with variable bin width, e.g, equal area of all blocks, or the "essential histogram" (doi:10.1093/biomet/asz081). The same effect (with facet_*) is of course already possible using geom_rect().

The required code additions would be minimal and follow the same idea as #1890

A simple illustration how this could work is given below:

df <- data.frame(
    x = c(rexp(1000), rexp(1000, 5)),
    study = c(rep("A", 1000), rep("B", 1000))
)
ggplot(df, aes(x)) +
    geom_histogram(aes(y = ..density..), breaks = function(x) qexp(c(0, .25, .5, .75, .95, .99), 1/mean(x))) +
    facet_wrap(vars(study))

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions