Skip to content

Instantly share code, notes, and snippets.

@will-r-chase
Created April 4, 2022 03:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save will-r-chase/7f1bcca260dae1bf922cea0f1e919dfe to your computer and use it in GitHub Desktop.
Save will-r-chase/7f1bcca260dae1bf922cea0f1e919dfe to your computer and use it in GitHub Desktop.
library(tidyverse)
plastics <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-01-26/plastics.csv')
bar_chart <-
plastics %>%
group_by(parent_company) %>%
summarize(total = sum(grand_total, na.rm = TRUE)) %>%
arrange(desc(total)) %>%
slice(4:14) %>%
mutate(parent_company = ifelse(parent_company == "NULL", "Unknown", parent_company)) %>%
ggplot() +
geom_col(aes(x = total, y = reorder(parent_company, total)), fill = "orchid4") +
theme_light() +
labs(title = "Top brands") +
theme(axis.title = element_blank(), panel.border = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.major.y = element_blank(),
plot.title.position = "plot")
pie_chart <-
plastics %>%
group_by(year) %>%
summarize(total = sum(grand_total, na.rm = TRUE)) %>%
ggplot() +
geom_bar(aes(x = "", y = total, fill = as.character(year)), stat = "identity", width = 1) +
coord_polar("y", start = 0) +
theme_minimal() +
labs(title = "Plastic pollution by year", fill = "") +
theme(axis.title = element_blank(), panel.grid = element_blank(),
axis.text = element_blank())
bar_chart_2 <-
plastics %>%
select(hdpe:pvc) %>%
pivot_longer(cols = 1:7) %>%
group_by(name) %>%
summarize(total = sum(value, na.rm = TRUE)) %>%
ggplot() +
geom_col(aes(x = total, y = reorder(name, total)), fill = "goldenrod") +
theme_light() +
labs(title = "By plastic type") +
theme(axis.title = element_blank(), panel.border = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.major.y = element_blank(),
plot.title.position = "plot")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment