library(tidyverse)data <-read_csv(here::here("data", "carbon-footprint-travel.csv"))data %>%mutate(type =case_when(str_detect(entity, "car|Motorcycle") ~"Private motorized transport",str_detect(entity, "flight") ~"Public air transport",str_detect(entity, "Ferry") ~"Public water transport",TRUE~"Public land transport" ) ) %>%ggplot(aes(x = emissions, y = forcats::fct_reorder(entity, -emissions), fill = type) ) +geom_col(orientation ="y", width = .8) +geom_text(aes(label =paste0(emissions, "g")),nudge_x =5,hjust =0,size =5,family ="Lato",color ="grey40" ) +scale_x_continuous(breaks =seq(0, 250, by =50), labels =function(x) glue::glue("{x} g"),expand =c(0, 0),limits =c(0, 285) ) +scale_fill_manual(values =c("#dfb468", "#8fb9bf", "#28a87d"), name =NULL, guide =guide_legend(reverse =TRUE) ) +labs(x =NULL, y =NULL,title ="Carbon footprint of travel per kilometer, 2018", subtitle ="The carbon footprint of travel is measured in grams of carbon dioxide equivalents per passenger kilometer.\nThis includes carbon dioxide, but also other greenhouse gases, and increased warming from aviation emissions at altitude.", caption ="Source: UK Department for Business, Energy & Industrial Grenhouse gas reporting: conversion factors 2019.\nNote: Data is based on official conversion factors used in UK reporting. These factors may vary slightly depending on the country.\nOriginal visualization by Hannah Ritchie, OurWorldInData.org | Makeover by Cédric Scherer" ) +theme_minimal(base_size =18, base_family ="Cabinet Grotesk") +theme(panel.grid.major =element_blank(),panel.grid.minor =element_blank(),axis.text =element_text(color ="grey30"),axis.text.y =element_text(face ="bold"),axis.text.x =element_blank(),legend.position =c(.75, .8),legend.text =element_text(size =20),legend.key.height =unit(2.6, "lines"),plot.title =element_text(family ="Cabinet Grotesk", size =40, color ="grey30", margin =margin(b =10)),plot.subtitle =element_text(size =17, color ="grey30", margin =margin(b =20)),plot.title.position ="plot",plot.caption =element_text(size =14, hjust =0, color ="grey60", margin =margin(t =20), lineheight =1.2),plot.caption.position ="plot",plot.margin =margin(15, 15, 15, 15) )ggsave("emissions.png", width =15, height =10)