为什么函数序列在ggplot2中不起作用?

3

我想使用函数序列提取一些绘图代码,如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

尝试这样做时,R会给出以下错误:

错误:ggplot2不知道如何处理类uneval的数据

使用简单的管道进行相同操作可以很好地运行:
iris %>% ggplot(aes(Sepal.Width, Sepal.Length)) + geom_point()

我的功能序列/代码有什么问题吗?
1个回答

5
我不太清楚为什么,但以下方法是可行的。(可能是因为在管道内使用 { 而不是 ( 以控制计算顺序。)
library(magrittr)
library(ggplot2)

plot_me <- . %>% {ggplot(., aes(Sepal.Width, Sepal.Length)) + geom_point()}
iris %>% plot_me

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接