I have a few functions which are called by a final function to draw ggplot graph. I am using a list to pass to function call so that the graph could be iterated through each of them. However, the xlab is not showing correctly.
first_plot <- function(dta, vari) {
vari <- enquo(vari)
dta %>%
group_by(!!vari) %>%
summarize(a = mean(!!whatever) +
ggplot(aes(x=!!vari)) +
geom_point(aes(a))
}
plot_all <- function(dta, item) {
list_var <- list(name = item)
plot_list<- list()
for(i in 1:length(item)) {
vari <- sym(item[i])
plot_list[[i]] <- first_plot(dta, vari)
}
}
If I pass plot_all(data, c('a','b','c'), I would expect the xlab would show a, b, c correspondingly but it always show vari. Can you help me to troubleshoot this?
Thanks.