I find my code inefficient and want to make it faster by iterating through factor variables in the dataset and use plot_grid() to combine these plots together. But I don't know how.
Here is the repetitive code I write a lot of times.
`3` <- customer_personal_profiles %>%
ggplot(aes(Education)) +
geom_bar() +
coord_flip() +
theme_bw()
`2` <-customer_personal_profiles %>%
ggplot(aes(EmploymentStatus)) +
geom_bar() +
coord_flip() +
theme_bw()
`1` <- customer_personal_profiles %>%
ggplot(aes(Gender)) +
geom_bar() +
coord_flip() +
theme_bw()
cowplot::plot_grid(`1`, `2`, `3`)
The code produced this graph:
I found the code quite lengthy and repetitive. Is there any way I can make it in several lines of code?
Thank you!