Tidyeval拼接运算符!!! ggplot的aes失败 [英] Tidyeval splice operator !!! fails with ggplot's aes

查看:91
本文介绍了Tidyeval拼接运算符!!! ggplot的aes失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ggplot2中讨论整洁评估的文章给出了的印象是aes()现在支持quaquoquoation.但是,我无法使其与unquote-splice运算符!!!一起使用.

The article discussing tidy evaluation in ggplot2 gives the impression that aes() now supports quasiquoation. However, I'm having problems getting it to work with the unquote-splice operator !!!.

library( ggplot2 )

## Predefine the mapping of symbols to aesthetics
v <- rlang::exprs( x=wt, y=mpg )

## Symbol-by-symbol unquoting works without problems
ggplot( mtcars, aes(!!v$x, !!v$y) ) + geom_point()

## But unquote splicing doesn't...
ggplot( mtcars, aes(!!!v) ) + geom_point()
# Error: Can't use `!!!` at top level
# Call `rlang::last_error()` to see a backtrace

(也许不足为奇)如果将美学贴图移至几何体,则会发生相同的事情:

(Perhaps unsurprisingly) The same thing happens if the aesthetic mapping is moved to the geom:

ggplot( mtcars ) + geom_point( aes(!!v$x, !!v$y) )   # works
ggplot( mtcars ) + geom_point( aes(!!!v) )           # doesn't

我缺少明显的东西吗?

推荐答案

这是因为aes()接受xy自变量,而!!!仅在点内有效.将来,我们将尝试解决此特定问题.在此期间,您需要分别取消对xy的引用,或使用以下解决方法:

That's because aes() takes x and y arguments and !!! only works within dots. We'll try to solve this particular problem in the future. In the interim you'll need to unquote x and y individually, or use the following workaround:

aes2 <- function(...) {
  eval(expr(aes(!!!enquos(...))))
}

ggplot(mtcars, aes2(!!!v)) + geom_point()

这篇关于Tidyeval拼接运算符!!! ggplot的aes失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆