Helper for creating an histogram
Usage
bb_histogram(
  bb,
  data,
  mapping = NULL,
  stacked = FALSE,
  fill = FALSE,
  bins = 30,
  binwidth = NULL,
  ...
)Arguments
- bb
- A - billboard- htmlwidgetobject.
- data
- A - data.frameor a- vector, the first column will be used to calculate density if- xis- NULL.
- mapping
- Mapping of variables on the chart, see - bbaes.
- stacked
- Logical, create a stacked histogram. 
- fill
- Logical, create a stacked percentage histogram. 
- bins
- Number of bins. Overridden by - binwidth. Defaults to 30.
- binwidth
- The width of the bins. See - geom_histogram
- ...
- Not used. 
Examples
data("diamonds", package = "ggplot2")
# one variable
billboarder() %>% 
  bb_histogram(data = diamonds, x = "price")
#> Warning: `aes_string()` was deprecated in ggplot2 3.0.0.
#> ℹ Please use tidy evaluation idioms with `aes()`.
#> ℹ See also `vignette("ggplot2-in-packages")` for more information.
#> ℹ The deprecated feature was likely used in the billboarder package.
#>   Please report the issue at <https://github.com/dreamRs/billboarder/issues>.
# with mapping
billboarder() %>% 
  bb_histogram(diamonds, bbaes(price))
# equivalent to
billboarder() %>% 
  bb_histogram(data = diamonds$price)
# prettier with 'binwidth'
# (but you need to know your data)
billboarder() %>% 
  bb_histogram(data = diamonds, x = "price", binwidth = 500) %>% 
  bb_colors_manual()
# with a grouping variable
billboarder() %>%
  bb_histogram(data = diamonds, x = "price",
               group = "cut", binwidth = 500)
# and with mapping
billboarder() %>%
  bb_histogram(diamonds, bbaes(price, group = cut),
               binwidth = 500)
# stacked histogram
billboarder() %>%
  bb_histogram(diamonds, bbaes(price, group = cut),
               stacked = TRUE, binwidth = 500)
# another example
dat <- data.frame(
  sample = c(rnorm(n = 500, mean = 1), rnorm(n = 500, mean = 2)),
  group = rep(c("A", "B"), each = 500)
)
billboarder() %>% 
  bb_histogram(data = dat, x = "sample", binwidth = 0.25)
samples_mean <- tapply(dat$sample, dat$group, mean)
billboarder() %>% 
  bb_histogram(data = dat, x = "sample", group = "group",
               binwidth = 0.25) %>% 
  bb_x_grid(
    lines = list(
      list(value = unname(samples_mean['A']),
           text = "mean of sample A"),
      list(value = unname(samples_mean['B']), 
           text = "mean of sample B")
    )
  )