Why don't functional sequences work with ggplot2?
dplyr, ggplot2, magrittr, r
Solution
I can't really explain why, but the following works.
(It might be because of the use of `{` instead of `(` to control the order of computation inside the pipe).
library(magrittr)
library(ggplot2)
plot_me <- . %>% {ggplot(., aes(Sepal.Width, Sepal.Length)) + geom_point()}
iris %>% plot_me
Problem
I would like to extract some plotting code using a functional sequence as described in http://www.r-bloggers.com/magrittr-1-5/. However, it does not work ``` require(magrittr); require(ggplot2); require(dplyr) plot_me <- . %>% (ggplot(aes(Sepal.Width, Sepal.Length)) + geom_point()) iris %>% plot_me ``` When trying this, R gives the following error Error: ggplot2 doesn't know how to deal with data of class uneval Doing the same using simple piping works nicely: ``` iris %>% ggplot(aes(Sepal.Width, Sepal.Length)) + geom_point() ``` What's wrong with my functional sequence/code?