Click the Original, Code and Reconstruction tabs to read about the issues and how they were fixed.
Objective
The objective of this pie chart is to inform and raise awareness of the countries most contributing to heat pollution by ranking the top 20 carbon emitting countries compared to the rest of the world. The target audience for this graph is the general public, in conjunction with political and commercial decision makers and the media.
The CO2 Emissions visualisation has the following three main issues:
Reference
The following code was used to fix the issues identified in the original.
library(readr)
library(tidyverse)
library(ggplot2)
ghg_emissions <- read_csv("C:/Users/Raelene/Desktop/Data Analytics/Semester 3/Data Visualisation and Communication/Assignment 2/ghg-emissions.csv")
emissions <- ghg_emissions %>% select('Country/Region', '2018')
emissions2 <- emissions %>% filter(row_number() <= n()-2)
emissions20 <- emissions %>% filter(`2018`>= 400.00)
total <- sum(emissions2$`2018`)
total20 <- sum(emissions20$`2018`)
emissions20 <- rbind(emissions20, c('Rest of the World', 12162.07))
emissions20$`2018` <- as.numeric(emissions20$`2018`)
Region <- c('Asia', 'Americas', 'Asia', 'Eurasia', 'Asia', 'Americas', 'Asia', 'Asia', 'Europe', 'Americas', 'Americas', 'Africa' , 'Asia', 'Asia', 'Oceania', 'Africa', 'Europe', 'Europe', 'Asia', 'Asia', 'Other')
emissions20 <- cbind(emissions20, Region)
cols <- c("Country", "CO2 Emissions", "Region")
colnames(emissions20) <- cols
emissions20$Country[12] = 'DR Congo' #for ease of reading and length
emissions20$Proportion <- emissions20$`CO2 Emissions`/total
emissions20$Percent <- emissions20$Proportion*100
plot <- ggplot(data = emissions20, aes(x = reorder(`Country`, -`Percent`), y= `Percent`, fill = factor(`Region`, levels = c('Asia', 'Americas', 'Eurasia', 'Europe', 'Africa', 'Oceania', 'Other'))))
plot2 <- plot + geom_bar(stat = "identity", position = "dodge") +
theme(legend.position="none") +
scale_fill_manual(values=c('#66c2a5', '#fc8d62', '#8da0cb', '#e78ac3', '#a6d854', '#ffd92f', '#e5c494')) +
facet_grid(~factor(`Region`, levels = c('Asia', 'Americas', 'Eurasia', 'Europe', 'Africa', 'Oceania', 'Other')),
scales="free_x",
space = "free_x",
switch = "x") +
theme(axis.text.x=element_text(angle=45,hjust=1)) +
labs(title="Carbon Emissions for the Top 20 Emitting Countries Grouped by Region, 2018",
y = 'Percentage of CO2 Emissions',
x = 'Country and Region',
fill = element_blank())+
geom_text(aes(label=round(Percent,1)), vjust = -0.5, size =3) +
theme(strip.placement = "outside",
strip.background = element_rect(fill = "white")) +
theme(panel.background = element_blank(),
axis.line = element_line(colour = "grey"))
strip_colours <- unique(ggplot_build(plot2)$data[[1]]$fill)
plot3 <- ggplot_gtable(ggplot_build(plot2))
strips <-which(startsWith(plot3$layout$name, 'strip'))
for (s in seq_along(strips)) {
plot3$grobs[[strips[s]]]$grobs[[1]]$children[[1]]$gp$fill <- strip_colours[s]
}
Data Reference
The following plot fixes the main issues in the original.