gf_squareplot: Countable-Rectangle Histogram

View source: R/gf_squareplot.R

gf_squareplotR Documentation

Countable-Rectangle Histogram

Description

[Experimental]

Usage

gf_squareplot(
  x,
  data = NULL,
  binwidth = NULL,
  origin = NULL,
  boundary = NULL,
  fill = "#7fcecc",
  color = "black",
  alpha = 1,
  na.rm = TRUE,
  mincount = NULL,
  bars = c("none", "outline", "solid"),
  xbreaks = NULL,
  xrange = NULL,
  show_dgp = FALSE,
  show_mean = FALSE,
  auto_subdivide = FALSE
)

Arguments

x

Formula (~variable) or numeric vector.

data

Data frame (required if x is a formula).

binwidth

Width of histogram bins. Auto-calculated if NULL.

origin

Starting position for bins.

boundary

Alias for origin.

fill

Rectangle fill color. Default "#7fcecc".

color

Rectangle border color. Default "black".

alpha

Transparency. Default 1.

na.rm

Remove NA values. Default TRUE.

mincount

Minimum y-axis height for consistent scaling.

bars

Display style: "none" (squares only), "outline", or "solid".

xbreaks

Number of x-axis breaks or vector of specific positions.

xrange

X-axis limits as c(min, max).

show_dgp

Show DGP annotation overlay. Default FALSE.

show_mean

Show dashed mean line. Default FALSE.

auto_subdivide

Split bins with >75 observations into sub-columns. Default FALSE.

Details

Creates histograms where individual data points are visible as stacked unit rectangles, making counts easy to visualize. Designed for teaching statistical concepts, particularly sampling distributions.

Value

A ggplot object with S3 class c("gf_squareplot", "gg", "ggplot").

Examples

gf_squareplot(~Thumb, data = Fingers)
gf_squareplot(~Thumb, data = Fingers, bars = "outline")

coursekata documentation built on March 11, 2026, 1:06 a.m.