Project Part II

Interactive and static data plots of source type CO2 emissions from 1920 to 2000.

  1. Install packages we will use to read in and plot the data.
  1. Read the data in from part I
source_type_co2 <- read_csv(here::here("source_type_co2.csv"))

Interactive Graph

source_type_co2 %>% 
  pivot_longer(cols = 2:7, names_to ="source_type", values_to = "amount") %>% 
  group_by(source_type) %>%
  mutate(Year = paste(Year, "12", "31", sep = "-")) %>% 
  e_charts(x = Year) %>% 
  e_river(serie = amount, legend=FALSE) %>%
  e_tooltip(trigger = "axis") %>% 
  e_title(text = "Annual CO2 Emissions, by source type",
          subtext = "(in billions of tonnes). Source: Our World in Data",
          sublink = "https://ourworldindata.org/grapher/co2-by-source",
          left = "center") %>% 
  e_theme("roma")

Static Graph

source_type_co2 %>% 
  pivot_longer(cols = 2:7, names_to ="source_type", values_to = "amount") %>% 
  group_by(source_type) %>% 
  ggplot(aes(x = Year, y = amount, fill=source_type)) +
  geom_area() +
  theme_classic() +
  theme(legend.position = "bottom") +
  labs( y = "in billions of tonnes",
        fill = NULL)

ggsave(filename = here::here("_posts/2022-05-12-project-part-ii/preview.png"))