bcat_plt_hist: Histogram utility

View source: R/bcat_plt_hist.R

bcat_plt_histR Documentation

Histogram utility

Description

Create a histogram using ggplot2 graphics with UC styling. Includes optional density curve overlay and mean reference line.

Usage

bcat_plt_hist(
  df,
  x,
  bins = NULL,
  fill = palette_UC[["Steger Silver"]],
  facet = NULL,
  density = FALSE,
  mean_line = TRUE,
  rug = FALSE,
  x_lab = ggplot2::waiver(),
  y_lab = ggplot2::waiver(),
  title = ggplot2::waiver(),
  subtitle = ggplot2::waiver(),
  caption = ggplot2::waiver(),
  legend_position = "bottom",
  legend_hide = FALSE,
  x_scale = NULL,
  y_scale = NULL,
  facet_scale = c("fixed", "free_y", "free_x", "free"),
  nrow = NULL,
  ncol = NULL,
  x_refline = NULL,
  y_refline = NULL
)

Arguments

df

The data to be displayed.

x

Variable to map to the x-axis.

bins

Number of bins. If NULL (default), uses ggplot2's automatic selection.

fill

Fill color for bars. Default is UC Steger Silver.

facet

Facetting variable(s). Wrap in vars().

density

Logical. Overlay density curve? Default is FALSE.

mean_line

Logical. Draw dashed vertical line at mean? Default is TRUE.

rug

Logical. Add rug plot at bottom? Default is FALSE.

x_lab

Label for x-axis.

y_lab

Label for y-axis.

title

Plot title.

subtitle

Plot subtitle.

caption

Plot caption.

legend_position

Legend position: "bottom" or "right".

legend_hide

Logical. Hide legend?

x_scale

scale_x_ function.

y_scale

scale_y_ function.

facet_scale

Facet scales: "fixed", "free", "free_x", "free_y".

nrow

Number of facet rows.

ncol

Number of facet columns.

x_refline

Vector of x-values for vertical reference lines.

y_refline

Vector of y-values for horizontal reference lines.

Value

A ggplot object.

Author(s)

Saannidhya Rawat

See Also

Other plots: bcat_plt_area(), bcat_plt_bar(), bcat_plt_box(), bcat_plt_coef(), bcat_plt_diag(), bcat_plt_line(), bcat_plt_point(), bcat_plt_ts()

Examples

library(ggplot2)

# Basic histogram
bcat_plt_hist(mtcars, x = mpg)

# With density curve and mean line
bcat_plt_hist(mtcars, x = mpg, density = TRUE, mean_line = TRUE)

# Faceted by cylinders
bcat_plt_hist(mtcars, x = mpg, facet = vars(cyl), facet_scale = "free_x")

Rbearcat documentation built on March 21, 2026, 5:07 p.m.