Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

as_reference

Create a reference to a layer for use in other filters


Description

This function is basically synonymous with with_raster() but exist to make the intend of marking a layer with a specific id clear.

Usage

as_reference(x, id = NULL, include = is.null(id))

Arguments

x

A ggplot2 layer object, a ggplot, a grob, or a character string naming a filter

id

A string identifying this layer for later use

include

Should the layer itself be included in the graphic

Value

Depending on the input, either a grob, Layer, list of Layers, guide, or element object. Assume the output can be used in the same context as the input.

See Also

Other layer references: as_colourspace(), as_group()

Examples

library(ggplot2)

ggplot() +
  as_reference(
    geom_point(aes(20, 300), size = 100, colour = 'white'),
    id = 'mask_layer'
  ) +
  with_mask(
    geom_point(aes(mpg, disp), mtcars, size = 5),
    mask = 'mask_layer'
  )

ggfx

Pixel Filters for 'ggplot2' and 'grid'

v1.0.0
MIT + file LICENSE
Authors
Thomas Lin Pedersen [aut, cre] (<https://orcid.org/0000-0002-5147-4711>), RStudio [cph, fnd]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.