gg_histo: Histograms with options for auto-binning

View source: R/gg_histo.R

gg_histoR Documentation

Histograms with options for auto-binning

Description

Function to plot histograms with specified bin width. See reference: https://www.answerminer.com/blog/binning-guide-ideal-histogram.

Usage

gg_histo(
  data,
  var,
  binw_select = "FD",
  facet = NULL,
  alpha = 0.8,
  fill = "steelblue",
  colour = "black",
  theme_for_histo = theme_minimal(),
  title = NULL,
  subtitle = NULL
)

Arguments

data

Data frame or tibble

var

Variable to be plotted

binw_select

Specify method to calculate the bin width. "FD" for Freedman-Diaconis (1981) (default), "Sturges" for Sturges (1926), "Scott" for Scott (1979), "Square-root" for Square-root (N/A), or "Rice" for Rice (1944).

facet

Variable name to facet wrap by. Default is NULL.

alpha

How solid / transparent should the fill be.

fill

Fill colour for histrogram.

colour

Outline colour of histogram blocks.

theme_for_histo

Specify the ggplot theme. Default is theme_minimal().

title

The main title of the plot

subtitle

A subtitle for the plot

Examples

library(tidyverse)

gg_histo(data = diamonds,
         var = price,
         binw_select = "Sturges",
         facet = NULL)

gg_histo(data = diamonds,
         var = price,
         binw_select = "Scott",
         facet = clarity)

gg_histo(data = diamonds,
         var = price,
         binw_select = "FD",
         facet = clarity)

gg_histo(data = diamonds,
         var = price,
         binw_select = "Square-root",
         facet = clarity)

ggplot(data = diamonds, aes(x = price)) +
  geom_density(alpha = 0.4,
               fill = "darkgreen") +
  theme_minimal()


emilelatour/laviz documentation built on Oct. 15, 2023, 1:41 p.m.