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

with_raster

Convert a layer to a raster


Description

This filter simply converts the given layer, grob, or ggplot to a raster and inserts it back again. It is useful for vector graphics devices such as svglite if a layer contains a huge amount of primitives that would make the file slow to render. as_reference(x, id) is a shorthand for with_raster(x, id = id, include = FALSE) that makes the intent of using this grob or layer as only a filter reference clear.

Usage

with_raster(x, ...)

Arguments

x

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

...

Arguments to be passed on to methods. See the documentation of supported object for a description of object specific arguments.

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.

Examples

library(ggplot2)
ggplot(mtcars, aes(mpg, disp)) +
  with_raster(geom_point(data = mtcars, size = 3))

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.