Learn R Programming

loon.ggplot (version 1.0.1)

gg_pipe: Pipe ggplot object

Description

Pack a ggplot object forward to ggplot2loon expressions via a pipe-operator "%>%".

Usage

gg_pipe(data, ggObj)

Arguments

data

a data frame to use for ggplot

ggObj

a ggplot object to be passed though

Value

a ggplot evaluate object

Details

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.

Examples

Run this code
# NOT RUN {
if(require(magrittr) && interactive()) {
# }
# NOT RUN {
 # Error
 g <- mtcars %>%
    ggplot(aes(mpg, wt, colour = cyl)) +
    geom_point() %>%
    ggplot2loon()
# }
# NOT RUN {
 g <- mtcars %>%
   gg_pipe(
     ggplot(aes(mpg, wt, colour = cyl)) + geom_point()
   ) %>%
   ggplot2loon()
}
# }

Run the code above in your browser using DataLab