Created
January 12, 2021 06:01
-
-
Save perlatex/5789bf653860fcd734baebd99eae987e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
relig_income <- relig_income %>% | |
pivot_longer(!religion, names_to = "income", values_to = "count") | |
relig_income | |
relig_income %>% count(religion) | |
relig_income %>% | |
group_nest(religion) | |
relig_income %>% | |
group_by(religion) %>% | |
group_map( | |
~ggplot(.x, aes(x = income, y = count)) + | |
geom_bar(stat = "identity", position = "dodge") + | |
ggtitle(.y) | |
) | |
relig_income %>% | |
group_split(religion) %>% | |
purrr::map( | |
~ggplot(.x, aes(x = income, y = count)) + | |
geom_bar(stat = "identity", position = "dodge") + | |
ggtitle(.x$religion) | |
) | |
relig_names <- c("Evangelical Prot", "Catholic") | |
relig_income %>% | |
filter(religion %in% relig_names) %>% | |
group_by(religion) %>% | |
group_walk( | |
~ggsave( | |
paste0(.y, "plot.png"), | |
ggplot(data = .x, aes(x = income, y = count)) + | |
geom_bar(stat = "identity", position = "dodge"), | |
width = 6, | |
height = 4, | |
dpi = 300, | |
device = 'png' | |
) | |
) %>% | |
invisible() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment