The %L+%
(L-plus) operator allows you to add components to a ggloop
object - whether that object is a:
lhs %L+% rhs # S3 method for gglist +(lhs, rhs)
ggloop()
: either a nested
list of ggplot
objects or a list of ggplot
object, but can
also be a single ggplot
object.ggplot2
package.%L+%
borrows HEAVILY from magrittr
, and in fact uses the same
yet-tweaked functions as magrittr, minus a few others. It is a substitute for
+
and is used in the same fashion: to add geoms, stats, aesthetics,
facets, and other features to ggplot
object. The returned object from
ggloop()
is often a nested list of ggplot
objects. However it
is possible to use %L+%
in place of where +
would normally be
used. This is due to the conditional statements present in %L+%
's
structure.
# Add component to entire list. g <- ggloop(mtcars, aes_loop(x = mpg:hp, y = mpg:hp)) g <- g %L+% ggplot2::geom_point()#> Warning: The special infix operator `%L+%` will be deprecated. Please use `+` as you would for 'ggplot2'.# Add component to a subset of a list g2 <- ggloop(mtcars, aes_loop(x = disp:wt, y = disp:wt, color = c(cyl, gear))) g2$color.gear <- g2$color.gear %L+% ggplot2::geom_point()#> Warning: The special infix operator `%L+%` will be deprecated. Please use `+` as you would for 'ggplot2'.#> Error in lapply(lhs, function(x) { x + rhs}): object 'g2' not foundg2$color.cyl[1:3] <- g2$color.cyl[1:3] %L+% ggplot2::geom_point()#> Warning: The special infix operator `%L+%` will be deprecated. Please use `+` as you would for 'ggplot2'.#> Error in lapply(lhs, function(x) { x + rhs}): object 'g2' not foundg2$color.cyl$x.hp_y.drat <- g2$color.cyl$x.hp_y.drat %L+% ggplot2::geom_point()#> Warning: The special infix operator `%L+%` will be deprecated. Please use `+` as you would for 'ggplot2'.#> Error in first(g2$color.cyl$x.hp_y.drat, ggplot2::geom_point()): object 'g2' not found