ggsubset: Passing a subset of data to ggplot2 layers.

View source: R/conveniences.R

ggsubsetR Documentation

Passing a subset of data to ggplot2 layers.

Description

This is a convenience function to allow layer objects, such as geoms, to take a subset of the data in the main ggplot() call, without storing a duplicate of the subset in the ggplot object.

Usage

ggsubset(rowtest = NULL, omit = NULL)

Arguments

rowtest

logical expression indicating which rows to keep.

omit

a character column name to exclude.

Details

ggsubset is a wrapper around subset.data.frame where the subset argument is set to rowtest and the select argument to -omit. Since the data argument in the layer() function can take a function with one argument, we can pass the function returned from ggsubset as that argument to subset the data by rows.

Value

A function that takes a data.frame as argument and returns a subset of that data.frame according to rowtest

See Also

See ggplot2::layer(), specifically the data argument. See subset.data.frame() for the internal function.

Examples

ggplot(iris, aes(Sepal.Width, Sepal.Length)) +
  geom_point(data = ggsubset(Species == "setosa"))

ggh4x documentation built on May 29, 2024, 6:47 a.m.