Skip to content

Instantly share code, notes, and snippets.

@brodieG
Last active November 29, 2017 20:19
Show Gist options
  • Select an option

  • Save brodieG/0793724c2bc782a95244a4657a88a7c9 to your computer and use it in GitHub Desktop.

Select an option

Save brodieG/0793724c2bc782a95244a4657a88a7c9 to your computer and use it in GitHub Desktop.
Turn Ggplot into a Pipe Operated Machine
`%>%` <- function(lhs, rhs) UseMethod("%>%")
`%>%.default` <- magrittr::`%>%`
`%>%.gg` <- function(lhs, rhs) ggplot2:::`+.gg`(lhs, rhs)
# WARNING: IF YOU DO THE FOLLOWING YOU SHOULD PROBABLY EXIT AND
# RESTART YOUR R SESSION SO THAT MAGRITTR IS RESTORED TO ITS
# ORIGINAL STATE.
assignInNamespace("is_pipe",
function (pipe)
{
identical(pipe, quote(`%>%`)) || identical(pipe, quote(`%T>%`)) ||
identical(pipe, quote(`%<>%`)) || identical(pipe, quote(`%$%`)) ||
identical(pipe, quote(`%>%.default`))
},
"magrittr"
)
iris %>% ggplot() %>% geom_point(aes(x=Sepal.Width, y=Sepal.Length, color=Species))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment