I would like to pass variable name to var and do all sorts of things including ggplot.
Apparently UQ works for data manipulation, but doesn't work for ggplot2. So my function "foo" works but "foo1" doesn't.
What's the best solution?
set.seed(100)
dat <- tibble(`a` = rbinom(100, 1, 0.2), `b` = rnorm(100))
foo <- function(var)
{
var_q <- enquo(var)
dat %>% mutate(`d` = UQ(var_q) + 1)
}
foo(`a`)
foo1 <- function(var)
{
var_q <- enquo(var)
dat %>% mutate(`d` = UQ(var_q) + 1) %>% ggplot(aes(x=UQ(var_q), y=`b`)) + geom_point()
}
foo1(`a`)