with_blend {ggfx}R Documentation

Blend a layer with a reference

Description

This filter blends the layer with a reference according to one of many rules as laid out in the Details section.

Usage

with_blend(
  x,
  bg_layer,
  blend_type = "over",
  flip_order = FALSE,
  alpha = NA,
  ...
)

Arguments

x

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

bg_layer

The background layer to use. Can either be a string identifying a registered filter, or a raster object. The map will be resized to match the dimensions of x.

blend_type

The type of blending to perform. See Details

flip_order

Should the order of the background and the overlay be flipped so that bg_layer is treated as being on top and x being below.

alpha

For non-Duff-Porter blends the alpha channel may become modified. This argument can be used to set the resulting alpha channel to that of the source ("src") or destination ("dst")

...

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

Details

Two images can be blended in a variety of ways as described below. In the following source will refer to the top-most image, and destination to the bottom-most image. Note that which is which can be controlled with the flip_order argument.

Duff-Porter alpha blend modes

This is a set of well-defined blend types for composing two images, taking their opacity into account:

Mathmathical blend modes

These blend modes perform often complex channel operations based on the different channel values in the source and destination:

Lighting blend modes

These blend modes are designed to provide different lighting effects:

Channel copying blends

These blend modes copies a single channel from the source to the destination

Special blends

The above is obviously a very quick overview. More information can be found in https://legacy.imagemagick.org/Usage/compose/

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 blend filters: with_blend_custom(), with_interpolate(), with_mask()

Examples

library(ggplot2)
ggplot() +
  as_reference(
    geom_text(aes(0.5, 0.5, label = 'Blend Modes!'), size = 10, fontface = 'bold'),
    id = "text"
  ) +
  with_blend(
    geom_polygon(aes(c(0, 1, 1), c(0, 0, 1)), colour = NA, fill = 'magenta'),
    bg_layer = "text",
    blend_type = 'xor'
  )


[Package ggfx version 1.0.1 Index]