Layer operation products
Source:R/class-operation-product.R
, R/operation-.R
, R/operation-adjust.R
, and 2 more
operation_product.Rd
operations can be multiplied together to form chains of operations, which when multiplied by (applied to) layer-like objects, return modified layer-like objects.
Usage
# S4 method for operation,ANY
*(e1, e2)
# S4 method for ANY,operation
*(e1, e2)
# S4 method for adjust,adjust
*(e1, e2)
# S4 method for nop,nop
*(e1, e2)
# S4 method for operation,nop
*(e1, e2)
# S4 method for operation_sum,nop
*(e1, e2)
# S4 method for nop,operation
*(e1, e2)
# S4 method for nop,operation_sum
*(e1, e2)
# S4 method for operation
prod(x, ..., na.rm = FALSE)
# S4 method for operation,operation
*(e1, e2)
# S4 method for numeric,operation
*(e1, e2)
# S4 method for operation,numeric
*(e1, e2)
# S4 method for operation,operation_sum
*(e1, e2)
# S4 method for operation_sum,operation
*(e1, e2)
# S4 method for operation_sum,operation_sum
*(e1, e2)
Arguments
- e1
an operation, layer-like, or
numeric()
- e2
an operation, layer-like, or
numeric()
- x, ...
- na.rm
ignored
Value
An operation.
Details
Multiplication of ggblend operations depends on the types of objects being multiplied:
If you multiply an operation with an operation, they are merged into a single operation that applies each operation in sequence.
If you multiply an operation with a layer-like object, that operation is applied to the layer, returning a new layer-like object.
If you multiply an operation by a
numeric()
n, a new operation that repeats the input operation is n times is returned.
Examples
library(ggplot2)
# multiplying operations by numerics repeats them...
adjust(color = "red") * 2
#> <operation>: (adjust(colour = "red") + adjust(colour = "red"))
# multiplying operations together chains (or merges) them
adjust(color = "red") * adjust(linewidth = 2)
#> <operation>: adjust(colour = "red", linewidth = 2)
# multiplication obeys the distributive law
op = (adjust(aes(y = 11 -x), color = "skyblue") + 1) * (adjust(color = "white", linewidth = 4) + 1)
op
#> <operation>: (adjust(aes(y = ~11 - x), colour = "white", linewidth = 4) + adjust(aes(y = ~11 - x), colour = "skyblue") + adjust(colour = "white", linewidth = 4) + 1)
# 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 = 2) * op