operation_composition {ggblend}R Documentation

Layer operation composition

Description

operations can be composed together to form chains of operations, which when multiplied by (applied to) layer-like objects, return modified layer-like objects. In contrast to operation_products, compositions of operations are not distributive over sums of operations or layer-like objects.

Details

Operation composition is achieved through function application, typically using the pipe operator (⁠|>⁠); e.g. ⁠operation1 |> operation2⁠.

The output of composing ggblend operations depends on the types of objects being composed:

Value

An operation.

Examples


library(ggplot2)

# composing operations together chains them
adjust(color = "red") |> blend("multiply")

# unlike multiplication, composition does not follow the distributive law
mult_op = (adjust(aes(y = 11 -x), color = "skyblue") + 1) * blend("multiply")
mult_op

comp_op = (adjust(aes(y = 11 -x), color = "skyblue") + 1) |> blend("multiply")
comp_op

# multiplication by a geom returns a modified version of that geom
data.frame(x = 1:10) |>
  ggplot(aes(x = x, y = x)) +
  geom_line(linewidth = 10, color = "red") * comp_op


[Package ggblend version 0.1.0 Index]