I have the following data set (sample):
train <- data.frame(ps_ind_06_bin = c(FALSE, FALSE, FALSE, TRUE, TRUE, FALSE),
ps_ind_07_bin = c(FALSE, TRUE, TRUE, FALSE, TRUE, TRUE),
ps_ind_08_bin = c(TRUE, TRUE, TRUE, FALSE, TRUE, FALSE),
ps_ind_09_log = c(1, 3, 4, 2, 3, 2))
I have the following function that shows a ggplot for a group_by()
operation:
get_charts1 <- function(mygroup){
quo_var <- enquo(mygroup)
train %>%
group_by(!!quo_var) %>%
count() %>%
ungroup() %>%
ggplot(aes_q(x = quo_var, y = quote(n), fill = quo_var)) +
geom_col() +
theme(legend.position = "none")
}
It works fine when I manually imput a column name, for example:
get_charts1(ps_ind_07_bin)
However, I want to use the function on several columns, which I put on a vector:
binarias <- train %>%
select(ends_with("bin")) %>%
colnames()
Using map and taking some suggestions, I tried to use:
listaplots <- map(quo(!!! syms(binarias)), get_charts1)
But this gives me the following error:
"Error: Can't splice at top-level"
Does anyone know what I need to do to get this to work?