gg_pipe | R Documentation |
Pack a ggplot
object forward to ggplot2loon
expressions
via a pipe-operator "%>%".
gg_pipe(data, ggObj)
data |
a data frame to use for ggplot |
ggObj |
a ggplot object to be passed though |
When "+" and "%>%" both appear in pipe operations, "%>%" takes the priority of "+",e.g:
mtcars %>%
ggplot(aes(mpg, wt, colour = cyl)) +
geom_point() %>%
ggplot2loon()
,
error would occur. The reason is
geom_point() %>% ggplot2loon()
would run before
ggplot(aes(mpg, wt, colour = cyl)) + geom_point()
.
Hence, we need a function gg_pipe()
to pack the ggplot
object and force operations happen in order.
a ggplot
evaluate object
if(requireNamespace("magrittr") && interactive()) {
## Not run:
# Error
g <- mtcars %>%
ggplot(aes(mpg, wt, colour = cyl)) +
geom_point() %>%
ggplot2loon()
## End(Not run)
g <- mtcars %>%
gg_pipe(
ggplot(aes(mpg, wt, colour = cyl)) + geom_point()
) %>%
ggplot2loon()
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.