Skip to contents

Draws boxplots for a numeric variable, optionally grouped by a categorical variable. Group means and a reference line for the overall mean can optionally be overlaid.

Usage

plotBox(x, ...)

# Default S3 method
plotBox(
  x,
  g = NULL,
  main = NULL,
  xlab = "",
  ylab = "",
  ylim = NULL,
  col = NULL,
  grid = TRUE,
  means = TRUE,
  stamp = TRUE,
  ...
)

# S3 method for class 'formula'
plotBox(
  formula,
  data,
  subset,
  na.action = na.omit,
  main = NULL,
  xlab = "",
  ylab = "",
  ylim = NULL,
  col = NULL,
  grid = TRUE,
  stamp = TRUE,
  ...
)

Arguments

x

numeric vector, or a formula of the form x ~ g.

...

graphical parameters. Parameters recognized by the internal graphics framework are applied via par(); remaining arguments are forwarded to graphics::boxplot().

g

optional grouping variable (ignored if a formula is used).

main

main title of the plot.

xlab

label for the x-axis.

ylab

label for the y-axis.

ylim

numeric vector of length 2 specifying the y-axis limits. If NULL (default), the range of x is used.

col

vector of colors. If NULL, a palette is generated automatically.

grid

controls drawing of the background grid. Can be:

  • TRUE: draw grid with default settings

  • FALSE, NULL, or NA: suppress grid

  • a named list: arguments passed to graphics::grid(), e.g. list(col = "red", nx = NA, ny = NULL) for vertical lines only

means

controls drawing of group means and an overall mean reference line. Can be:

  • TRUE: draw with default settings

  • FALSE, NULL, or NA: suppress

  • a named list: arguments passed to the internal means function. Supported arguments: col, pch, cex, lcol, lty, lwd.

stamp

controls the corner stamp. .useTheme (default) resolves to getTheme()$stamp. TRUE/FALSE/NULL, or an explicit string, as for .withGraphicsState() (internal).

formula

A formula of the form y ~ group.

data

an optional data frame containing variables in the formula.

subset

optional expression indicating which observations to use.

na.action

a function specifying how missing values are handled.

Value

Invisibly returns NULL.

Details

Optional plot components are controlled using bedrock::callIf() semantics:

  • TRUE: draw with defaults

  • FALSE, NULL, or NA: suppress component

  • named list: customize component arguments

Examples

if (FALSE) { # \dontrun{
set.seed(1)
x <- rnorm(100)
g <- sample(c("A", "B"), 100, TRUE)

plotBox(x)
plotBox(x, g)

plotBox(x ~ g)
} # }