Skip to content

Instantly share code, notes, and snippets.

@will-r-chase
Created April 4, 2022 00:54
Show Gist options
  • Save will-r-chase/d2511b67790f05b1cbadb03399384c45 to your computer and use it in GitHub Desktop.
Save will-r-chase/d2511b67790f05b1cbadb03399384c45 to your computer and use it in GitHub Desktop.
##Solution
library(tidyverse)
#plastic pollution dataset
plastics <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-01-26/plastics.csv')
#wrangle data
data <- 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))
#how I did it
ggplot(data) +
geom_col(aes(x = total, y = reorder(parent_company, total)), fill = "orchid4") +
labs(title = "Plastic items collected on beaches, by manufacturer") +
scale_x_continuous(labels = scales::label_comma()) +
theme(
axis.title = element_blank(),
panel.background = element_blank(),
panel.grid.major.y = element_blank(),
panel.grid.minor.y = element_blank(),
axis.ticks.y = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.major = element_line(color = "#e7e7e7", size = 0.4),
axis.ticks = element_line(color = "#e7e7e7", size = 0.4)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment