Click the Original, Code and Reconstruction tabs to read about the issues and how they were fixed.
Objective
The purpose of visualisation is to depict the impact of Covid-19 to the World economies. The article discusses about the change in Government Debt to GDP ratio in all countries due to the impacts of the Pandemic namely, - higher spending to stimulate their economies & - reduced tax revenue due to lockdowns and virus.
The audience of the article is general public with a purpose of informing general public of the severity of the economic impact on countries due to the pandemic.
The Visualisation is based on the data sourced from International Monetory Fund.
The visualisation chosen had the following three main issues:
These issues are addressed and resolved in the code as follows:
Reference
The following code was used to fix the issues identified in the original.
# Calling the neccessary libraries:
library(ggplot2)
library(dplyr)
library(patchwork)
library(ggrepel)
library(stringr)
library(tidyr)
library(tinytex)
# Data Reading
# Read IMF Data on World Debt Ratio for Countries
imfdm1 <- read.csv('imf-dm-export-20230723.csv')
# Read list of countries by Continent and trim String type fields
continents <- read.csv('list-of-countries-by-continent-2023.csv')
# Data Cleansing
# Remove "no data" rows specific to Year 2021
imfdm <- imfdm1 %>% filter(X2021 != "no data")
# trim String type fields
imfdm$country <- str_trim(imfdm$country)
continents$country <- str_trim(continents$country)
continents$continent <- str_trim(continents$continent)
# Attach Continent to Countries and select only the necessary columns
# NOTE: Some of the names of the countries were to be manually updated to match the two data sources.
countries <- imfdm %>% left_join(continents, c("country")) %>% select(country, continent, X2019, X2021)
countries <- countries %>% rename('2019' = X2019, '2021' = X2021)
# Convert the Debt Ratios to Double
countries$'2021' <- as.double(countries$'2021')
countries$'2019' <- as.double(countries$'2019')
# reduce length of the name of the Countries to improve visualisation real estate
countries$country_pref <- str_sub(countries$country, end = 10)
# Create new column for pre-pandemic to post-pandemic Debt Ration difference
countries$DR_diff <- (countries$'2021' - countries$'2019')
# Pivot two years and create two columns "year" and "debt_ratio"
countries <- pivot_longer(countries, cols = 3:4, names_to = "year", values_to = "debt_ratio")
# Split Countries to Continents
continent_splits <- split(countries, countries$continent)
# Function for creating a common ggplot layers for each Continent
ggp_function <- function(arg_continent) {
data <- arg_continent
contin <- first(data$continent)
ggplot(data, aes(x = debt_ratio, y = reorder(country_pref, DR_diff))) +
geom_line() +
geom_point(aes(color = year), size = 1.5) +
scale_color_brewer(palette = "Set1", direction = -1) +
xlim(c(0, 260)) +
labs(subtitle=contin, y="Country", x="Debt Ratio (%)") +
theme(axis.text=element_text(size= 5),
axis.title=element_text(size= 8),
plot.subtitle = element_text(size = 10,face="bold"))
}
# Separate Continents
paf <- ggp_function(continent_splits$Africa)
pas <- ggp_function(continent_splits$Asia)
peu <- ggp_function(continent_splits$Europe)
poc <- ggp_function(continent_splits$Oceania)
pna <- ggp_function(continent_splits$'North America')
psa <- ggp_function(continent_splits$'South America')
Data Reference
Data, IMF DATAMAPPER, DATASETS, Global Debt Database Section (2023). General Government Debt. Retrieved July 23, 2023, from International Monetory Fund website: https://www.imf.org/external/datamapper/GGXWDG_NGDP@WEO/OEMDC/ADVEC/WEOWORLD/VEN?year=2023
List of Countries by Continent section (2023) List of Countries by Continent 2023. Retrieved July 23, 2023, from World Population Review website: https://worldpopulationreview.com/country-rankings/list-of-countries-by-continent
The following plot fixes the main issues in the original.
The following plot fixes the main issues in the original.