bcat_plt_box: Box plot / violin plot utility

View source: R/bcat_plt_box.R

bcat_plt_boxR Documentation

Box plot / violin plot utility

Description

Create a box plot or violin plot with UC styling. Includes optional jittered point overlay and outlier highlighting.

Usage

bcat_plt_box(
  df,
  x,
  y,
  fill = NULL,
  facet = NULL,
  violin = FALSE,
  jitter = TRUE,
  jitter_width = 0.2,
  notch = FALSE,
  order = FALSE,
  coord_flip = FALSE,
  alpha = 0.3,
  x_lab = ggplot2::waiver(),
  y_lab = ggplot2::waiver(),
  title = ggplot2::waiver(),
  subtitle = ggplot2::waiver(),
  caption = ggplot2::waiver(),
  legend_lab = ggplot2::waiver(),
  legend_position = "bottom",
  legend_hide = FALSE,
  x_scale = NULL,
  y_scale = NULL,
  fill_scale = scale_fill_UC(),
  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

Categorical variable for the x-axis.

y

Numeric variable for the y-axis.

fill

Variable to map to fill aesthetic. If NULL, uses x for coloring.

facet

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

violin

Logical. Use violin plot instead of box plot? Default is FALSE.

jitter

Logical. Overlay jittered points? Default is TRUE.

jitter_width

Jitter width. Default is 0.2.

notch

Logical. Add notches? Default is FALSE.

order

Logical. Reorder x by median of y? Default is FALSE.

coord_flip

Logical. Flip coordinates? Default is FALSE.

alpha

Point transparency. Default is 0.3.

x_lab

Label for x-axis.

y_lab

Label for y-axis.

title

Plot title.

subtitle

Plot subtitle.

caption

Plot caption.

legend_lab

Legend title.

legend_position

Legend position.

legend_hide

Logical. Hide legend?

x_scale

scale_x_ function.

y_scale

scale_y_ function.

fill_scale

scale_fill_ function.

facet_scale

Facet scales.

nrow

Number of facet rows.

ncol

Number of facet columns.

x_refline

Vertical reference lines.

y_refline

Horizontal reference lines.

Value

A ggplot object.

Author(s)

Saannidhya Rawat

See Also

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

Examples

library(ggplot2)

# Basic box plot
bcat_plt_box(mtcars, x = factor(cyl), y = mpg)

# Violin plot
bcat_plt_box(mtcars, x = factor(cyl), y = mpg, violin = TRUE)

# Ordered and flipped
bcat_plt_box(mtcars, x = factor(cyl), y = mpg, order = TRUE, coord_flip = TRUE)

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