Skip to content

Instantly share code, notes, and snippets.

@perlatex
Created January 12, 2021 06:01
Show Gist options
  • Save perlatex/5789bf653860fcd734baebd99eae987e to your computer and use it in GitHub Desktop.
Save perlatex/5789bf653860fcd734baebd99eae987e to your computer and use it in GitHub Desktop.
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