loading...

The function gg() should be used like this: gg$geom_point(). It transforms on the fly an original ggplot2 function supposed to be used with the + operator (like p + geom_point()) into a pipeable version (like p %>% gg$geom_point()).

gg(ggplot, ...)

# S3 method for subsettable_gg
$(x, name)

# S3 method for subsettable_gg
.DollarNames(x, pattern = "")

Arguments

ggplot

An object of class "ggplot" (or "theme").

...

Further arguments passed to the the ggplot function (see Details).

x

The gg()function.

name

The name of the ggplot function to make pipeable.

pattern

A regular expression to list matching names.

Value

The gg() function just returns an error message. When subsetted with the name of a ggplot2 function (e.g., gg$geom_point()), it returns a modified version of that function in such a way that it can be used with a pipe operator.

Details

The function returned by gg$fun is a modified version of the function fun where a first argument ggplot = is added, and the instruction ggplot + ... is added in its body. A message is also added in the body to explicitly warn about these changes. All the other arguments of fun remain valid and should keep their original meaning.

The changes are done on the fly, and the original function fun is not altered anywhere else (and in particular, no alteration is done in a package or a namespace). When using this construct, make sure that: (1) you understand what is done, (2) you are aware that you use an altered version of the original function, (3) a bug or strange behavior may occur due to the patch and the original author of the function is not responsible in this case (the problem must be reported to the author of gg() and the maintainer of the present package instead), and (4) the patched function exhibits an additional argument and behaves differently to what is described in the help page of the original, non-patched, function!

Examples

library(ggplot2)
data(iris)
ggplot(aes(x = Petal.Length, y = Sepal.Length, col = Species) , data = iris) |>
  gg$geom_point() |>
  gg$labs(x = "Sepal length (mm)", y = "Petal length (mm)")

# Also try completion with gg$<tab>