Click the Original, Code and Reconstruction tabs to read about the issues and how they were fixed.
Objective
The objective of the visualization is to be informative and to provide insights on the global trade of major conventional weapons*. By providing a snapshot of the magnitude of the trade and the key players in the market, the visualization aims at making arms’ trade data more accessible to the general public. The targetted audience is likely composed of university students, researchers, journalists, and professionals in fields such as business, politics and finance.
*(such as aircraft, artillery, radar systems, missiles, and ships designed for military use)
The visualization chosen had the following three main issues:
Reference
The following code was used to fix the issues identified in the original.
After downloading the source data from The World Bank website I save them in Excel format. I perform some very preliminary operations in Excel in order to clean the data and I subsequently import it in R.
# Importing data
library(readxl)
Exports_data <- read_excel("Arms_Trade_Data_v1.xlsx",
sheet = "Data_EX")
Imports_data <- read_excel("Arms_Trade_Data_v1.xlsx",
sheet = "Data_IM")
Mil_Exp_data <- read_excel("Arms_Trade_Data_v1.xlsx",
sheet = "Data_MIL_EXP_%GDP")
library(tidyverse)
library(dplyr)
Mil_Exp <- Mil_Exp_data |>
dplyr::mutate(Mil_Exp_2016 = round(Mil_Exp_2016, digits=2))
Exports <- Exports_data |>
# Show the data in Billion
dplyr::mutate(Exp_2016 = round(Exp_2016/10^9, 2)) |>
# Add the data on military expenditures
dplyr::left_join(Mil_Exp, by = 'Country_Code') |>
dplyr::select(c(1,2,3,5)) |>
dplyr::rename(Country_Name = Country_Name.x)
Imports <- Imports_data |>
# Show the data in Billion
dplyr::mutate(Imp_2016 = round(Imp_2016/10^9, 2)) |>
# Add the data on military expenditures
dplyr::left_join(Mil_Exp, by = 'Country_Code') |>
dplyr::select(c(1,2,3,5)) |>
dplyr::rename(Country_Name = Country_Name.x)
library(ggiraph)
library(sf)
library(tidyverse)
library(ggthemes)
library(patchwork)
# Building the pipe for ggplot ####
imports_gg <- Imports |>
dplyr::inner_join(rnaturalearth::ne_countries(returnclass = "sf") |>
dplyr::select(iso_a3, geometry),
by=c("Country_Code"="iso_a3")) |>
# Plot
ggplot()+
labs(title = 'Importers of Military Weapons',
caption = "Note: White countries correspond to NA values")+
# Using the interactive option and custom tooltip
geom_sf_interactive(aes(geometry=geometry, fill=Imp_2016,
tooltip=paste0(Country_Name,
"<br><b>Value:", Imp_2016,
"<br><i>Military Expenditures (%GDP):", Mil_Exp_2016 |> format(big.mark=" "))))+
scale_fill_stepsn_interactive(name ='US$ Bil', n.breaks=8, colors = c('#fff0f3', '#ffccd5', '#fbb1bd','#ff8fa3', '#ff5c8a','#c9184a','#B13356','#a4133c'), limits=c(0,3.5), na.value = 'white')+
theme_map()+
theme(plot.title = element_text(face='bold'))
# ggiraph ####
imports_girafe <- ggiraph::girafe(
ggobj = imports_gg)
#Importing packages
library(sf)
library(rnaturalearth)
library(ggiraph)
library(tidyverse)
library(ggthemes)
library(patchwork)
library(ggpubr)
# Building the pipe for ggplot ####
exports_gg <- Exports |>
dplyr::inner_join(rnaturalearth::ne_countries(returnclass = "sf") |>
dplyr::select(iso_a3, geometry),
by=c("Country_Code"="iso_a3")) |>
# Plot
ggplot()+
labs(title = 'Exporters of Military Weapons')+
# Using the interactive option and custom tooltip
geom_sf_interactive(aes(geometry=geometry, fill=Exp_2016,
tooltip=paste0(Country_Name,
"<br><b>Value:", Exp_2016,
"<br><i>Military Expenditures (%GDP):",Mil_Exp_2016 |> format(big.mark=" "))))+
scale_fill_stepsn_interactive(
name = "US$ Bil", n.breaks=10, limits=c(0, 10), colours = c('#a9d6e5', '#89c2d9','#61a5c2', '#468faf', '#2c7da0', '#2a6f97', '#014f86', '#01497c', '#013a63', '#012a4a'), na.value='white')+
theme_map()+
theme(plot.title = element_text(face='bold'))
# ggiraph ####
exports_girafe <- ggiraph::girafe(
ggobj = exports_gg)
# Combining the two plots into a unique figure
g <- wrap_plots(list(exports_gg, imports_gg), ncol = 1)
-By Country and Income Group
library(ggplot2)
mil_exp_plot <- Mil_Exp |>
ggplot(aes(x=Mil_Exp_2016, y=reorder(Country_Name, Mil_Exp_2016), fill=Mil_Exp_2016)) +
geom_bar(stat = 'identity')+
geom_text(aes(label=round(Mil_Exp_2016,1)), stat = 'identity', hjust = -0.5, size = 2)+
# Facet by Income Group
facet_wrap(~factor(Income_Group, levels= c('High income', 'Upper middle income', 'Lower middle income', 'Low income')), scales = 'free_y')+
scale_x_continuous(breaks=seq(0,13,1))+
labs(title='Military Expenditures (%GDP) by Country and Income Group*', caption = 'Note: Income Group is based on the World Bank classification', x='Military Expenditures (%GDP)', y=NULL)+
scale_fill_gradientn(colours = c('#d8f3dc','#b7e4c7','#95d5b2', '#74c69d', '#52b788', '#40916c', '#2d6a4f', '#1b4332'))+
theme_bw()+
theme(legend.position = 'none', plot.title = element_text(face='bold'))
Data Reference
The following plot fixes the main issues in the original.
❗Hover over each Country to find out the value of arms’ trade as well as the % of GDP spent in military expenses 🌎
Additional
I have additionaly constructed the faceted plot shown below. Countries are categorized by income group and are shown in decreasing order depending on their military expenditures (%GDP).
This plot can be used as a supplement to the main visualization. In fact it provides a clear and comparative view of how much each country is spending on their military in relation to their economic output -which can be useful to put data into a more informative context.