Hol*_*ndl 3 r ggplot2 dplyr magrittr
我想使用http://www.r-bloggers.com/magrittr-1-5/中描述的功能序列提取一些绘图代码.但是,它不起作用
require(magrittr); require(ggplot2); require(dplyr)
plot_me <- . %>% (ggplot(aes(Sepal.Width, Sepal.Length)) + geom_point())
iris %>% plot_me
Run Code Online (Sandbox Code Playgroud)
尝试此操作时,R会出现以下错误
错误:ggplot2不知道如何处理class uneval的数据
使用简单的管道做同样的工作很好:
iris %>% ggplot(aes(Sepal.Width, Sepal.Length)) + geom_point()
Run Code Online (Sandbox Code Playgroud)
我的功能序列/代码出了什么问题?
我无法解释为什么,但以下工作.
(这可能是因为使用{
而不是(
控制管道内的计算顺序).
library(magrittr)
library(ggplot2)
plot_me <- . %>% {ggplot(., aes(Sepal.Width, Sepal.Length)) + geom_point()}
iris %>% plot_me
Run Code Online (Sandbox Code Playgroud)