ggmisc: Misc functions with ggplot2

insert_layerR Documentation

Misc functions with ggplot2

Description

insert_layer() insert layers to an arbitrary position

mean_sd() calculates mean and sd for ggplot2::stat_summary().

label_none() removes strip.text while keeping strip.background.

Usage

insert_layer(p, ..., after = 0L)

mean_sd(x, mult = 1)

label_none(labels, ...)

Arguments

p

gg object

...

layers to add

after

position; 0L is back

x

numeric vector.

mult

number of multiples of standard error.

labels

Data frame of labels. Usually contains only one element, but faceting over multiple factors entails multiple label variables.

Examples

(ggplot2::ggplot(ggplot2::mpg) +
  ggplot2::aes(drv, hwy) +
  ggplot2::geom_boxplot(fill = "gold") +
  ggplot2::geom_dotplot(binaxis = "y", stackdir = "center", binwidth = 1, stackratio = 0.5) +
  ggplot2::stat_summary(fun.data = mean_sd, color = "red", size = 2, linewidth = 2) +
  ggplot2::facet_wrap(ggplot2::vars(drv), scale = "free_x", label = label_none)) |>
  insert_layer(ggplot2::geom_violin(fill = "darkorange"), after = -2L)

heavywatal/rwtl documentation built on June 13, 2025, 7:39 a.m.