Skip to contents

Add histogram

Usage

add_histogram(plot, binwidth = NULL, bins = NULL, ...)

Arguments

plot

A tidyplot generated with the function tidyplot().

binwidth

The width of the bins. Can be specified as a numeric value or as a function that calculates width from unscaled x. Here, "unscaled x" refers to the original x values in the data, before application of any scale transformation. When specifying a function along with a grouping structure, the function will be called once per group. The default is to use the number of bins in bins, covering the range of the data. You should always override this value, exploring multiple widths to find the best to illustrate the stories in your data.

The bin width of a date variable is the number of days in each time; the bin width of a time variable is the number of seconds.

bins

Number of bins. Overridden by binwidth. Defaults to 30.

...

Arguments passed on to the geom function.

Value

A tidyplot object

Examples

energy %>%
  tidyplot(x = power) %>%
  add_histogram()
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.


energy %>%
  tidyplot(x = power, color = energy_type) %>%
  add_histogram()
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.