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

with_dither

Dither image using Floyd-Steinberg error correction dithering


Description

This filter reduces the number of colours in your layer and uses the Floyd-Steinberg algorithm to even out the error introduced by the colour reduction.

Usage

with_dither(x, max_colours = 256, colourspace = "sRGB", ...)

Arguments

x

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

max_colours

The maximum number of colours to use. The result may contain fewer colours but never more.

colourspace

In which colourspace should the dithering be calculated

...

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.

See Also

Other dithering filters: with_circle_dither()

Examples

library(ggplot2)
ggplot(faithfuld, aes(waiting, eruptions)) +
  with_dither(
    geom_raster(aes(fill = density), interpolate = TRUE),
    max_colours = 10
  ) +
  scale_fill_continuous(type = 'viridis')

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.