View source: R/calc_bin_width.R
calc_bin_width | R Documentation |
There are many different methods that have been recommended over the years to determine an appropriate bin width for a histogram. This function collects those methods so that they are available easily. No one is really recommended over another. A few should be considered and then choose the best to visualize the distribution.
calc_bin_width(x, binw_select = "FD")
x |
A numeric object |
binw_select |
Character choice for which method to use to calculate bin width: "FD" (Default), "Sturges", "Scott", "Square-root", "Rice", "Shimazaki", "Juran" |
A numeric
https://en.wikipedia.org/wiki/Histogram#Square-root_choice https://stats.stackexchange.com/questions/798/calculating-optimal-number-of-bins-in-a-histogram https://arxiv.org/pdf/1612.07216.pdf https://cran.r-project.org/web/packages/essHist/essHist.pdf https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.170.173&rep=rep1&type=pdf https://www.neuralengine.org//res/histogram.html https://www.qimacros.com/histogram-excel/how-to-determine-histogram-bin-interval/#:~:text=Here's
library(ggplot2)
calc_bin_width(diamonds$carat, binw_select = "FD")
ggplot(data = diamonds,
aes(x = carat)) +
geom_histogram(colour = "white",
binwidth = calc_bin_width(diamonds$carat, binw_select = "FD"))
calc_bin_width(diamonds$carat, "Juran")
ggplot(data = diamonds,
aes(x = carat)) +
geom_histogram(colour = "white",
binwidth = calc_bin_width(diamonds$carat, binw_select = "Juran"))
ggplot(economics_long, aes(value)) +
facet_wrap(~variable, scales = 'free_x') +
geom_histogram(colour = "white",
binwidth = function(x) calc_bin_width(x, binw_select = "FD"))
ggplot(economics_long, aes(value)) +
facet_wrap(~variable, scales = 'free_x') +
geom_histogram(colour = "white",
binwidth = function(x) calc_bin_width(x, binw_select = "Sturges"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.