bb_histogram {billboarder} | R Documentation |
Helper for creating an histogram
Description
Helper for creating an histogram
Usage
bb_histogram(
bb,
data,
mapping = NULL,
stacked = FALSE,
fill = FALSE,
bins = 30,
binwidth = NULL,
...
)
Arguments
bb |
A |
data |
A |
mapping |
Mapping of variables on the chart, see |
stacked |
Logical, create a stacked histogram. |
fill |
Logical, create a stacked percentage histogram. |
bins |
Number of bins. Overridden by |
binwidth |
The width of the bins. See |
... |
Not used. |
Value
A billboard
htmlwidget
object.
See Also
Examples
data("diamonds", package = "ggplot2")
# one variable
billboarder() %>%
bb_histogram(data = diamonds, x = "price")
# 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")
)
)
[Package billboarder version 0.4.1 Index]