Why does ggplot plot flat lines here and how to make it just loop nicely one plot after the other and save them for futher use:
Var <- list()
mtcars$gear <- as.factor(mtcars$gear)
Var[["list"]][["var_resp"]] <-
c(
"mpg"
,"hp"
,"disp"
,"drat"
)
library(ggplot2)
for (n_var in Var[["list"]][["var_resp"]]) {
p <- ggplot(mtcars, aes(x = gear, y = n_var)) +
geom_boxplot()+
theme(legend.position = "none")
print(p)
}
My original data is in long format, still the same problem