Skip to contents

plot_box() builds a simple, pre-themed boxplot on one variable alone or grouped by another variable.

Usage

plot_box(
  data,
  formula,
  fill = "grey80",
  breaks = NULL,
  orient = c("vertical", "horizontal"),
  title = NULL,
  subtitle = c("show", "hide"),
  ...
)

Arguments

data

A data frame.

formula

Variables entered in formula notation. Either ~var for a one-variable boxplot or var1~var2 for a grouped boxplot where var2 is a grouping variable.

fill

The fill color for the boxplot. Entered as a character.

breaks

A vector of length 3 (start, stop, step) specifying how the x-scale should be broken up.

orient

The orientation for the plot (either "vertical", the default, or "horizontal"). As a shortcut, "v" and "h" may be used.

title

An override for the title of the plot. A sensible default is provided.

subtitle

A switch for hiding the default subtitle. One of "show" or "hide".

...

Extra title arguments passed on to ggformula::gf_labs() (which feeds to ggplot2::ggplot()).

Value

A ggplot object. In an interactive environment, results are viewable immediately.

Examples

plot_box(mtcars, ~wt)
#> Note: NAs always removed for boxplots
#> This message is displayed once per session.

plot_box(mtcars, wt~gear, fill = 'orangered4')

plot_box(mtcars, ~wt, breaks = seq(1, 6, 0.5))

plot_box(mtcars, wt~gear)

plot_box(mtcars, wt~gear, breaks = seq(1, 6, 0.5))