rasterise: Rasterise ggplot layers Takes a ggplot object or a layer as...

View source: R/rasterise.R

rasteriseR Documentation

Rasterise ggplot layers Takes a ggplot object or a layer as input and renders their graphical output as a raster.

Description

Rasterise ggplot layers Takes a ggplot object or a layer as input and renders their graphical output as a raster.

Usage

rasterise(input, ...)

## S3 method for class 'Layer'
rasterise(input, ..., dpi = NULL, dev = "cairo", scale = 1)

## S3 method for class 'list'
rasterise(input, ..., dpi = NULL, dev = "cairo", scale = 1)

## S3 method for class 'ggplot'
rasterise(
  input,
  ...,
  layers = c("Point", "Tile"),
  dpi = NULL,
  dev = "cairo",
  scale = 1
)

Arguments

input

ggplot plot object to rasterize

...

ignored

dpi

integer Sets the desired resolution in dots per inch (default=NULL).

dev

string Specifies the device used, which can be one of: "cairo", "ragg", "ragg_png" or "cairo_png" (default="cairo").

scale

numeric Scaling factor to modify the raster object size (default=1). The parameter 'scale=1' results in an object size that is unchanged, 'scale'>1 increase the size, and 'scale'<1 decreases the size. These parameters are passed to 'height' and 'width' of grid::grid.raster(). Please refer to 'rasterise()' and 'grid::grid.raster()' for more details.

layers

list of layer types that should be rasterized

Details

The default dpi (NULL (i.e. let the device decide)) can conveniently be controlled by setting the option "ggrastr.default.dpi" (e.g. options("ggrastr.default.dpi" = 30) for drafting).

Value

A modified Layer object.

Author(s)

Teun van den Brand <t.vd.brand@nki.nl>

Examples

require(ggplot2)
# `rasterise()` is used to wrap layers
ggplot(pressure, aes(temperature, pressure)) +
  rasterise(geom_line())

# The `dpi` argument controls resolution
ggplot(faithful, aes(eruptions, waiting)) +
  rasterise(geom_point(), dpi = 5)

# The `dev` argument offers a few options for devices
require(ragg)
ggplot(diamonds, aes(carat, depth, z = price)) +
  rasterise(stat_summary_hex(), dev = "ragg")

# The `scale` argument allows you to render a 'big' plot in small window, or vice versa.
ggplot(faithful, aes(eruptions, waiting)) +
  rasterise(geom_point(), scale = 4)

VPetukhov/ggrastr documentation built on June 28, 2023, 10:25 a.m.