Bump chart of Scottish greenhouse gas emissions

[This article was first published on R – scottishsnow, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The Ferret ran a piece today on Scotland’s greenhouse gas emissions. They did a great job of making their source data available, either through links or embedded into the their charts. I liked the first chart on the contributions of different sectors to the overall total, and thought it might work well as a bump chart.

I’ve used bump charts previously, for example in this analysis of voting patterns. One of the best things about coding is being able to reuse work. So it took 5 minutes to generate the plot below (code at the bottom).

If you’ve not seen a bump chart before, the category order is set by the magnitude at a given point on the x axis. So transport is currently the sector with the largest GHG emissions.

library(tidyverse)
library(ggalluvial)

df = read_csv("Downloads/ferret_data_ghg.csv") %>%
  rename(year = `Row Labels`) %>%
  pivot_longer(!year)

df %>%
  ggplot(aes(x = year, y = value, alluvium = name)) +
  geom_alluvium(aes(fill = name, colour = name),
                alpha = .75, decreasing = FALSE) +
  scale_colour_brewer(type = "qual", palette = "Paired") +
  scale_fill_brewer(type = "qual", palette = "Paired") +
  labs(title = "How do different economic sectors contribute\nto Scotland's Greenhouse Gas Emissions?",
       subtitle = "Data from https://theferret.scot/cop26-scotlands-greenhouse-gas-emissions-explained/",
       x = "Year",
       y = "GHG emissions (MtCO2e)",
       fill = "Sector",
       colour = "Sector") +
  theme_minimal() +
  theme(text = element_text(size = 20),
        plot.subtitle = element_text(size = 12))

To leave a comment for the author, please follow the link and comment on their blog: R – scottishsnow.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)