1

我怀疑这是处理 NSE 的问题。但是为什么这两种方法不起作用,我怎样才能让它们起作用。

temp1 <- function(x){
  iris %>% 
    ggplot(aes(Sepal.Length, Sepal.Width)) +
    geom_point() +
    facet_wrap(as.formula(paste("~", x)))
}
walk('Species', temp1)


temp2 <- function(x){
  x <- as.name(x)
  iris %>% 
    ggplot(aes(Sepal.Length, Sepal.Width)) +
    geom_point() +
    facet_wrap(~ x)
}
walk('Species', temp2)
4

1 回答 1

0

对我来说,这似乎不是 NSE 问题。如果你读到?walk它说(我强调):

walk() 调用 .f 的副作用并返回原始输入

尝试:

t <- walk('Species', temp1)
t
#[1] "Species"

我认为,如果您将显式打印添加到您的ggplot. 例如更改temp1为:

temp1 <- function(x){
  print(iris %>% 
        ggplot(aes(Sepal.Length, Sepal.Width)) +
        geom_point() +
        facet_wrap(as.formula(paste("~", x))))
}
于 2017-10-11T18:34:55.700 回答