Click the Original, Code and Reconstruction tabs to read about the issues and how they were fixed.
Objective
To inform a general audience interested in climate change issues, the contrast of nations that are the higher CO2 emittters with those nations that are most vulnerable to climate change. Both groups are almost mutually exclusive.
The visualisation chosen had the following three main issues:
Reference
The following code was used to fix the issues identified in the original.
library(readr)
library(dplyr)
library(stringr)
library(ggplot2)
library(extrafont)
#Source data
# Carbon Dioxide Information Analysis Center at Appalachian State University, Boone North Carolina, https://energy.appstate/CDIAC.
c_emissions <- read_csv("nation.1751_2016.csv", skip = 4)
# Notre Dame Global Adaptation Initiative, University of Notre Dame, https://gain.nd.edu/our-work/country-index/rankings/
gain <- read_csv("resources_2020_04_05_19h09/resources/gain/gain.csv")
# ISO 3166 Countries with Regional Codes, GitHub, https://github.com/lukes/ISO-3166-Countries-with-Regional-Codes/blob/master/all/all.csv
iso_country <- read_csv("iso_country.txt")
c_emissions$`Per capita CO2 emissions (metric tons of carbon)` <- c_emissions$`Per capita CO2 emissions (metric tons of carbon)` %>% parse_double(na= c("."), trim_ws = TRUE)
# Prepare data
# Filter 2016 emissions
c_emi_2016 <- c_emissions %>% filter(Year == 2016)
c_emi_2016 <- c_emi_2016 %>% select(1:3, 9)
names(c_emi_2016)[3] <- "tot_co2"
names(c_emi_2016)[4] <- "capita_co2"
# Clean up join column Nation
c_emi_2016 <- c_emi_2016 %>%
mutate(
Nation = str_replace_all(Nation, c(" AND " = " & ", " \\(.*\\)" = "", "UNITED STATES OF AMERICA" = "UNITED STATES", "DEMOCRATIC REPUBLIC OF THE CONGO" = "ZAIRE","COTE D IVOIRE" = "COTE D'IVOIRE", "BRUNEI DARUSSALAM"= "BRUNEI", "REPUBLIC OF " = "", "ISLAMIC IRAN" = "IRAN", "UNITED TANZANIA" = "TANZANIA", "LAO PEOPLE S DEMOCRATIC REPUBLIC" = "LAO PEOPLE'S DEMOCRATIC REPUBLIC", "PLURINATIONAL STATE OF BOLIVIA" = "BOLIVIA", "GUINEA BISSAU" = "GUINEA-BISSAU", "RUSSIAN FEDERATION" = "RUSSIA", "LAO PEOPLE'S DEMOCRATIC REPUBLIC" = "LAOS", "UNITED ARAB EMIRATES" = "U A E", "CENTRAL AFRICAN REPUBLIC" = "C A R"))
)
# Filter 2016 Gains & clean join column
gain_2016 <- gain %>% select(ISO3, Name, `2016`)
gain_2016 <- gain_2016 %>%
mutate(
Nation = toupper(Name) %>% str_replace_all(c(" AND " = " & ",", REPUBLIC OF" = "", ", BOLIVARIAN REPUBLIC O" = "", "BRUNEI DARUSSALAM"= "BRUNEI", ", UNITED REPUBLIC OF" = "", ", ISLAMIC REPUBLIC OF" = "", "CONGO, THE DEMOCRATIC REPUBLIC O" = "ZAIRE", ", PLURINATIONAL STATE OF" = "", "RUSSIAN FEDERATION" = "RUSSIA","LAO PEOPLE'S DEMOCRATIC REPUBLIC" = "LAOS", "UNITED ARAB EMIRATES" = "U A E", "CENTRAL AFRICAN REPUBLIC" = "C A R"))
)
names(gain_2016)[3] <- "gain"
# Join data sets for viz data
vizdata <- c_emi_2016 %>% inner_join(gain_2016 , by = "Nation")
#Only use completed cases : where nation has both emission and gain information.
vizdata <- vizdata[complete.cases(vizdata), ]
#Join to get continent info.
vizdata <- vizdata %>% inner_join(iso_country, by = c("ISO3" = "alpha-3"))
#Prepare viz data : factors, ranks for both emissions and gains. Filter top emitters and most vulnerable. And categorise them.
vizdata$Nation <- vizdata$Nation %>% factor()
vizdata$ISO3 <- vizdata$ISO3 %>% factor()
vizdata <- vizdata %>% mutate (
rnk_capco2 = rank(-capita_co2, ties.method = "min"),
rnk_vulnerable = rank(gain, ties.method = "min")
)
top_countries <- 30
cat_lbl1 <- paste(top_countries, "Most vulnerable")
cat_lbl2 <- paste("Top", top_countries, "CO2 emitters")
cat_lbl3 <- "Both"
vizdata <- vizdata %>% filter(rnk_capco2 <= top_countries | rnk_vulnerable <= top_countries)
vizdata <- vizdata %>% mutate(
cat = case_when(
rnk_vulnerable <= top_countries & rnk_capco2 > top_countries ~ cat_lbl1,
rnk_vulnerable > top_countries & rnk_capco2 <= top_countries ~ cat_lbl2,
TRUE ~ cat_lbl3
)
)
vizdata$cat <- vizdata$cat %>% factor(levels = c(cat_lbl2, cat_lbl1, cat_lbl3))
vizdata$region <- vizdata$region %>% factor(levels = c("Africa" , "Americas", "Asia" , "Europe" , "Oceania" ))
# configure and plot viz
#colour palette
pal <- c('#377eb8','#ffbe0b','#e41a1c','#ff7f00','#984ea3')
#background colour
backgrd <- "grey95"
plt <- vizdata %>% ggplot(aes(x = gain, y=capita_co2 ))
plt <- plt +
geom_point(aes(colour=region), stat = "identity", position = "identity", size=6, alpha = 0.75) +
geom_text( aes(label = str_wrap(str_to_title(Nation), width=8)), size=2.25 , hjust = 0.5, vjust = 0.5 , alpha = 0.8, check_overlap = TRUE) +
facet_grid(rows = vars(cat), scales = "free_y") +
labs (
x= "More Vulnerability to climate change (ND-Gain Index) Less",
y = expression("Emitted CO"[2]*" per capita (metric tons of carbon)"),
title = expression("The Dichotomy : CO"[2]*" emission and climate change vulnerability (2016)"),
subtitle = "African nations the lowest emitters and most vulnerable. Asian/European nations are the top emitters",
caption = "Source: CDIAC, Appalachian State University, https://energy.appstate.edu/research/work-areas/cdiac-appstate\nNotre Dame Global Adaptation Initiative, University of Notre Dame, https://gain.nd.edu/our-work/country-index/rankings"
) +
scale_colour_manual( values = pal) +
theme_gray() +
theme(
text=element_text(family="Arial"),
legend.title = element_blank(),
plot.background = element_rect(fill=backgrd),
panel.background = element_rect(fill = backgrd),
legend.background = element_rect(fill = backgrd),
panel.grid.minor.x = element_blank(),
panel.grid.minor.y = element_blank(),
axis.ticks = element_blank(),
plot.caption= element_text(size=7.5, hjust=1, margin=margin(t=15)),
plot.subtitle = element_text(size=10)
)
Data Reference
The following plot fixes the main issues in the original.