Skip to content

Adding trim for StatBin #3449

@wjakethompson

Description

@wjakethompson

I'm adding a color aesthetic to a faceted histogram. In the reprex below, with no color aesthetic, the histogram only show data within that facet level. However, with color defined, a baseline is added which stretches the stretches to include the range of data across all facets. The ideal behavior would be something similar to geom_density with trim = TRUE.

library(tidyverse)

set.seed(9416)
data <- tibble(a = rchisq(1000, df = 3),
               b = rchisq(1000, df = 1),
               c = rchisq(1000, df = 10)) %>%
  gather()

ggplot(data, aes(x = value)) +
  geom_histogram() +
  facet_wrap(~ key, ncol = 1)
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

ggplot(data, aes(x = value)) +
  geom_histogram(color = "red") +
  facet_wrap(~ key, ncol = 1)
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

ggplot(data, aes(x = value)) +
  geom_density(color = "red", trim = TRUE) +
  facet_wrap(~ key, ncol = 1)

Created on 2019-07-22 by the reprex package (v0.3.0)

Based on this response on StackOverflow, it seems like it would be fairly straightforward to add a trim argument to StatBin. Is this something you would consider/accept a PR for?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions