gbox: Box plot

View source: R/zzz-r4vn-graphs.R View source: R/graphs.R

gboxR Documentation

Box plot

Description

Draws one or several numeric distributions overall or across categories. vars() can request several numeric outcomes; hierarchical by is supported.

Usage

gbox(
  data = NULL, x = NULL, y = NULL, vars = NULL, by = NULL, horizontal = FALSE,
  points = FALSE, outliers = TRUE, xlab = NULL, ylab = NULL, xtitle = NULL,
  ytitle = NULL, xbreaks = NULL, ybreaks = NULL, title = NULL,
  subtitle = NULL, note = NULL, color = NULL, palette = "default",
  alpha = 0.7, border_color = "gray30", point_color = "black",
  point_alpha = 0.45, point_size = 0.55, point_pch = 16, xline = NULL,
  yline = NULL, ref_color = "gray40", ref_lty = 2, ref_lwd = 1,
  theme = "journal", size = 11, combine = FALSE, ncol = NULL, file = NULL,
  width = 7, height = 5, dpi = 300, show = TRUE, bg = "white", vline = NULL,
  hline = NULL
)

Arguments

data

A data frame. It may be omitted when an active R4VN data frame exists.

x

Optional categorical grouping variable.

y

Numeric outcome variable.

vars

Optional vars(...) selector used to request several variables in one call.

by

Optional grouping variable or hierarchical vars(...) specification.

horizontal

Draw horizontal boxes.

points

Add lightly jittered observations.

outliers

Show conventional box-plot outliers.

xlab

Optional category labels. Use an unnamed vector in displayed order or a named vector such as c(M = "Male", F = "Female").

ylab

Optional y-axis tick labels.

xtitle, ytitle

Axis titles. Variable names or variable labels are used automatically when possible.

xbreaks, ybreaks

Numeric tick positions used with xlab and ylab.

title, subtitle, note

Main title, subtitle, and note.

color

A color name or vector of colors. When NULL, palette is used.

palette

One of "default", "journal", "blue", "green", "warm", "gray", or "colourblind"; alternatively, a color vector.

alpha

Color opacity from 0 to 1.

border_color

Box/whisker border colour.

point_color, point_alpha, point_size, point_pch

Colour, transparency, size, and point symbol for overlaid raw observations.

xline, yline

Optional numeric reference lines on the x and y axes. Thus xline draws vertical lines and yline draws horizontal lines.

ref_color, ref_lty, ref_lwd

Color, line type, and width for reference lines; vectors are recycled for multiple lines.

theme

Graph theme: "journal", "clean", "minimal", or "classic".

size

Base font size.

combine

When several graphs are produced, draw them as labelled panels in one figure.

ncol

Optional number of columns in a combined figure.

file

Optional output file ending in png, jpg, tiff, pdf, or svg.

width, height

Output width and height in inches.

dpi

Resolution for raster output.

show

Draw the graph in the current graphics device.

bg

Background color for exported files.

vline, hline

Deprecated aliases for xline and yline.

Value

An object of class r4vn_graph; its data component contains group sample sizes and five-number summaries.

Examples

d <- data.frame(sex = factor(c("Male", "Female", "Female", "Male")), bmi = c(22, 24, 27, 21))
gbox(d, y = bmi)
gbox(d, x = sex, y = bmi, points = TRUE)

# Extended usage examples

d <- data.frame(sex = factor(c("Male", "Female", "Female", "Male")),
                bmi = c(22, 24, 27, 21))
gbox(d, y = bmi, show = FALSE)
gbox(d, x = sex, y = bmi, points = TRUE, show = FALSE)
gbox(d, x = sex, y = bmi, horizontal = TRUE, outliers = FALSE, show = FALSE)


R4VN documentation built on Sept. 30, 2026, 5:13 p.m.