R 为什么ggplot文档中的aes tidyeval示例会抛出错误?

R 为什么ggplot文档中的aes tidyeval示例会抛出错误?,r,ggplot2,dplyr,R,Ggplot2,Dplyr,我正试图围绕ggplot编写包装函数,但在取消引用函数参数时,我一直遇到一个错误: Error in !enquo(x) : invalid argument type 我已经重新阅读了dplyr编程指南,并认为我理解了它,并且以前在使用dplyr动词(如group_by和mutate)实现函数时使用了tidyeval。这让我想到了我发现这个例子的地方: scatter_by <- function(data, x, y) { ggplot(data) + geom_point(ae

我正试图围绕ggplot编写包装函数,但在取消引用函数参数时,我一直遇到一个错误:

Error in !enquo(x) : invalid argument type
我已经重新阅读了dplyr编程指南,并认为我理解了它,并且以前在使用dplyr动词(如group_by和mutate)实现函数时使用了tidyeval。这让我想到了我发现这个例子的地方:

scatter_by <- function(data, x, y) {
  ggplot(data) + geom_point(aes(!!enquo(x), !!enquo(y)))
}
scatter_by(mtcars, disp, drat)
我使用的是ggplot2版本2.2.1和dplyr 0.7.4


我尝试过使用rlang::UQ(enquo(x))而不是!!但是我仍然得到一个错误。

您可以使用
aes\u string
quo\u name

scatter_by <- function(data, x, y) {

  ggplot(data) + 
    geom_point(aes_string(x= quo_name(enquo(x)), y=quo_name(enquo(y))))

}
scatter_by(mtcars, disp, drat)

scatter\u谢谢您的回复和链接。aes应该支持tidyeval而不需要使用aes_字符串,不是吗?这使得我的包装器函数可以工作,根据它应该提供的文档,我想要一个更整洁的版本,但显然它不工作。我在DPLYR0.7.4和0.7.5上检查了它,但没有成功。也许值得在ggplot2的github上报告它?您的代码似乎很好,在我的电脑上也运行良好,我使用的是ggplot版本:
ggplot2_2.2.1.9000
在ggplot2中使用tidyeval是一项功能,它将成为其中的一部分,我相信这一功能即将实现。如果现在想使用该功能,可以安装开发版本。
scatter_by <- function(data, x, y) {

  ggplot(data) + 
    geom_point(aes_string(x= quo_name(enquo(x)), y=quo_name(enquo(y))))

}
scatter_by(mtcars, disp, drat)