R Tidyeval拼接运算符!!!使用ggplot'失败;s aes
给人的印象是R Tidyeval拼接运算符!!!使用ggplot'失败;s aes,r,ggplot2,tidyeval,R,Ggplot2,Tidyeval,给人的印象是aes()现在支持准液化。但是,我在使用unquote拼接操作符时遇到了问题 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_po
aes()
现在支持准液化。但是,我在使用unquote拼接操作符时遇到了问题代码>
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
我遗漏了一些明显的东西吗?那是因为aes()
接受x
和y
参数和代码>仅在点内有效。我们将来会设法解决这个特殊的问题。在此期间,您需要分别取消引用x
和y
,或者使用以下解决方法:
aes2 <- function(...) {
eval(expr(aes(!!!enquos(...))))
}
ggplot(mtcars, aes2(!!!v)) + geom_point()
aes2有了新的rlang更新,我认为您可以使用{{}在ggplot内部工作
polo<- function(x,y, data, by) {
ggplot({{data}}, aes(x = {{x}}, y = {{y}})) +
geom_point() +
facet_grid(rows = vars({{by}}))
}
polo(data = mtcars, x = cyl, y = mpg, by = vs )
谢谢你,莱昂内尔。
polo<- function(x,y, data, by) {
ggplot({{data}}, aes(x = {{x}}, y = {{y}})) +
geom_point() +
facet_grid(rows = vars({{by}}))
}
polo(data = mtcars, x = cyl, y = mpg, by = vs )