get_stat_layer: Isolate a stat layer from a plot

View source: R/layers.R

get_stat_layerR Documentation

Isolate a stat layer from a plot

Description

get_stat_layer returns a stat layer from a plot along with the global data sets and aesthetic mappings that the layer may inherit from.

Usage

get_stat_layer(p, stat = NULL, i = NULL)

Arguments

p

A ggplot object

stat

A character string found in the suffix of a ggplot2 stat function, e.g. "bin".

i

A numerical index, e.g. 1.

Details

Users can specify a layer in one of 3 ways:

  1. By order of appearance with i. The first layer to appear in the plot (the one drawn first, on the bottom) corresponds to i = 1.

  2. By type of stat with stat. get_stat_layer will return the first layer that uses the stat

  3. By a combination of stat and i. get_stat_layer will return the ith layer that uses the stat

Value

An object with class layer_to_check to be manipulated further with ggcheck functions.

Examples

require(ggplot2)
p <- ggplot(data = diamonds, aes(price)) +
  stat_bin(bins = 20, binwidth = 500)

get_stat_layer(p, i = 1)
get_stat_layer(p, stat = "bin")

rstudio-education/ggcheck documentation built on May 12, 2023, 11:33 a.m.