我尝试创建一个允许绘制ggvis
绘图的简单函数。我知道我必须在这里使用非标准评估,这就是我使用包intercept
功能的原因lazyeval
:
test_fn <- function(data,xvar, yvar){
plot <-
data %>%
ggvis(lazyeval::interp(~x, x = as.name(xvar)),
lazyeval::interp(~y, y = as.name(yvar))) %>%
layer_points()
return(plot)
}
编辑:
此功能工作正常:
test_fn(mtcars,'mpg', 'qsec')
但是为了给定的命令有效,我还应该做什么:
test_fn(mtcars,mpg, qsec)