Last Update: November 05, 2022 - 11:23
Table of Contents
Introduction
Governance consists of the traditions and institutions by which authority in a country is exercised. This includes the process by which governments are selected, monitored, and replaced; the government’s capacity to effectively formulate and implement sound policies; and the respect of citizens and the state for the institutions that govern economic and social interactions among them.
This report is based on the data source Worldwide-Governance-Indicators (Sep 23, 2022), which highlights six broad indicators of a country’s governance. The data includes results from 1996 to 2021.
Motivation
As a worldwide traveler who has just recently been in an almost 3-month study abroad program in Europe - traveling across 13 different countries, I have always been curious to understand the indicators that determine the success of a nation and how they are compared between one another. For that reason, when navigating through https://www.worldbank.org/ looking for some dataset to perform analyses, I found the one on which this report is based, so I decided to explore it.
Dataset
The dataset lists composite governance indicators based on over 30 underlying data sources. As mentioned in the introduction, it reports on six broad dimensions of governance for over 215 countries and territories over the period 1996-2021, which are:
- Control of Corruption;
- Government Effectiveness;
- Political Stability and Absence of Violence;
- Regulatory Quality;
- Rule of Law;
- Voice and Accountability.
Feel free to download the raw data from the link below if you also want to explore it in-depth!
Data Preparation
For ease of understanding and to make our analyses more transparent, during the data preparation stage, I filtered the indicators by their estimates which give each country a score on the aggregate hand, in units of standard normal distribution, ranging from approximately -2.5 to 2.5.
I have attached below the prepared data that I used throughout this report. You are welcome to explore the code, manipulate the data, or download it in the format you wish from the table below.
# 1_Importing
# url <- "https://databank.worldbank.org/data/download/WGI_csv.zip"
# directory <- getwd()
# tf <- tempfile(tmpdir = directory, fileext = ".zip")
# download.file(url, tf)
# unzip(tf)
df_data <- read_csv("WGIData.csv")
df_country <- read_csv("WGICountry.csv")
df_continent <- countrycode::codelist %>% select(continent, wb, country.name.en, iso2c, unicode.symbol)
# 2_Cleaning
df_data <- df_data %>%
clean_names() %>%
select(-c("indicator_code","x28")) %>%
pivot_longer(-c("country_name", "country_code", "indicator_name"),
names_to = "year",
values_to = "value") %>%
mutate(year = str_remove_all(year, pattern = "x")) %>%
filter(str_detect(indicator_name, "Estimate")) %>%
mutate(indicator_name = str_extract(indicator_name, pattern = "(.*):"),
indicator_name = str_remove_all(indicator_name, ":")) %>%
mutate(year = as.integer(year),
value = as.double(value))
df_country <- df_country %>%
clean_names() %>%
select(country_code, table_name, region)
df_continent <- df_continent %>%
clean_names() %>%
rename(country_code = wb,
country_name = country_name_en)
# 3_Creating_Master_Table
df <- df_data %>%
inner_join(df_country %>% select(country_code, region),
by = "country_code") %>%
inner_join(df_continent %>% select(country_code, continent, iso2c, unicode_symbol),
by = "country_code") %>%
mutate_all(~str_trim(., side = "both")) %>%
mutate(continent = case_when(region == "Latin America & Caribbean" ~ "South America",
region == "North America" ~ "North America",
country_name == "Greenland" ~ "North America",
T ~ continent)) %>%
mutate(continent = case_when(country_name == "Mexico" ~ "North America",
T ~ continent)) %>%
mutate(indicator_name = case_when(indicator_name == "Political Stability and Absence of Violence/Terrorism" ~ "Political Stability",
T ~ indicator_name)) %>%
mutate(year = as.integer(year),
value = as.double(value),
value = round(value, 2)) %>%
filter(continent != "") %>%
filter(value != "") %>%
select(-region) %>%
arrange(year, country_name)
# DATA TABLE
# Preparing
dt <- df %>%
select(country_name, country_code, continent, indicator_name, year, value) %>%
mutate_at(.vars = c("country_name", "country_code", "indicator_name", "year") ,~as_factor(.)) %>%
arrange(continent) %>%
mutate(continent = as_factor(continent)) %>%
arrange(year, country_name) %>%
# Creating
DT::datatable(rownames = FALSE,
width = "100%",
filter = "top",
colnames = c('Country','Code', 'Continent', 'Indicator', "Year", "Score"),
class = 'cell-border stripe',
extensions = c("Responsive", "Buttons"),
options = list(
autowidth = TRUE,
lengthMenu = c(6, 12, 25, 50),
dom = "Blfrtip",
buttons = c("copy", "csv", "excel", "print", "pdf"),
initComplete = JS("function(settings, json) {",
"$(this.api().table().header()).css({'background-color': '#c23d1d', 'color': '#fff'});",
"}")))
# htmlwidgets::saveWidget(dt, file = "WGI_DT.html")
# write_csv(df, file = "./WGI_cleaned.csv")
print(df)
## # A tibble: 27,591 × 8
## country_name country_code indicator_name year value conti…¹ iso2c unico…²
## <chr> <chr> <chr> <int> <dbl> <chr> <chr> <chr>
## 1 Afghanistan AFG Control of Corru… 1996 -1.29 Asia AF "\U000…
## 2 Afghanistan AFG Government Effec… 1996 -2.18 Asia AF "\U000…
## 3 Afghanistan AFG Political Stabil… 1996 -2.42 Asia AF "\U000…
## 4 Afghanistan AFG Regulatory Quali… 1996 -2.09 Asia AF "\U000…
## 5 Afghanistan AFG Rule of Law 1996 -1.79 Asia AF "\U000…
## 6 Afghanistan AFG Voice and Accoun… 1996 -1.91 Asia AF "\U000…
## 7 Albania ALB Control of Corru… 1996 -0.89 Europe AL "\U000…
## 8 Albania ALB Government Effec… 1996 -0.69 Europe AL "\U000…
## 9 Albania ALB Political Stabil… 1996 -0.34 Europe AL "\U000…
## 10 Albania ALB Regulatory Quali… 1996 -0.47 Europe AL "\U000…
## # … with 27,581 more rows, and abbreviated variable names ¹continent,
## # ²unicode_symbol
Visualizations
As this is a significant project involving many variables and records, I created five charts to understand the results better.
Correlation between Indicators (Correlation Matrix)
Most recent results 2021 by Country (Interactive Map)
Comparison by Continent (Box Plot)
Comparison between the top 3 Countries of 2021 (Line Chart)
USA progression over time (Animated Line Chart)
Most of the charts are interactive! If you see a [Full Screen] option next to a chart, it means the chart is interactive and you can view it in full screen.
Correlation between Indicators
The correlation chart below shows the connection between indicators.
For purposes of text space in the chart below, I have shortened the indicator’s names:
Corruption = Control of Corruption;
Effectiveness = Government Effectiveness;
Stability = Political Stability and Absence of Violence;
Regulations = Regulatory Quality;
Law = Rule of Law;
Voice = Voice and Accountability.
# Correlation Matrix
df_cor <- df %>%
select(country_name:continent) %>%
pivot_wider(names_from = "indicator_name",
values_from = "value") %>%
select(5:10) %>%
rename(Corruption = 1,
Effectiveness = 2,
Stability = 3,
Regulations = 4,
Law = 5,
Voice = 6) %>%
corrr::correlate(quiet = TRUE) %>%
corrr::rearrange()
# Correlation Plot
cor_plot <- df_cor %>%
GGally::ggcorr(low = "#abc3ff",
mid = "#ff6432",
high = "#0048ff",
label = TRUE,
label_round = 2,
label_color = "white",
label_size = 6,
legend.size = 12,
digits = 2,
limits = c(0, 1),
midpoint = 0.4,
palette = NULL,
geom = "tile",
hjust = 0.5,
vjust = 1,
size = 4.5,
angle = 0) +
# ggtitle("Indicators Correlation") +
cowplot::theme_cowplot() +
theme(plot.title = element_text(size = 22, hjust = .5))
## Warning in GGally::ggcorr(., low = "#abc3ff", mid = "#ff6432", high =
## "#0048ff", : data in column(s) 'term' are not numeric and were ignored
print(df_cor)
## # A tibble: 6 × 7
## term Effectiveness Regulations Law Corruption Voice Stability
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Effectiveness NA 0.932 0.929 0.918 0.752 0.714
## 2 Regulations 0.932 NA 0.903 0.865 0.781 0.667
## 3 Law 0.929 0.903 NA 0.937 0.822 0.789
## 4 Corruption 0.918 0.865 0.937 NA 0.772 0.750
## 5 Voice 0.752 0.781 0.822 0.772 NA 0.688
## 6 Stability 0.714 0.667 0.789 0.750 0.688 NA
print(cor_plot)
Most recent results 2021 by Country
The map below shows the 2021 results for each country.
As this is an interactive map, for you to see the scores, you will need to hover the mouse over the country, and then you will see the results of all six indicators, including the mean.
df_2021 <- df %>%
mutate(value = round(value, 2)) %>%
filter(year == "2021") %>%
select(country_name, country_code, indicator_name, value) %>%
pivot_wider(names_from = "indicator_name",
values_from = "value") %>%
clean_names() %>%
rowwise() %>%
mutate(mean = mean(c_across(3:8)),
mean = round(mean, 2))
# Highcharter
map_df_2021 <- hcmap(map = "custom/world-robinson-lowres",
download_map_data = FALSE,
data = df_2021,
value = "mean",
borderColor = "black",
borderWidth = .7,
nullColor = "#d3d3d3",
joinBy = c("iso-a3", "country_code")) %>%
hc_colorAxis(stops = color_stops(colors = viridisLite::mako(10, begin = 0.01))) %>%
hc_title(text = "<b>WGI Results 2021</b><i>(by Country)</i>",
margin = 5,
floating= FALSE,
align = "center",
style = list(fontSize = "28px",
color = "#252223",
useHTML = TRUE)) %>%
# hc_subtitle(text = "<i>2021</i>",
# margin = 20,
# floating= FALSE,
# align = "center",
# style = list(fontSize = "28px",
# color = "#e1a615",
# useHTML = TRUE)) %>%
hc_mapNavigation(enabled = TRUE,
enableMouseWheelZoom = TRUE,
enableDoubleClickZoom = TRUE) %>%
hc_exporting(enabled = TRUE,
filename = "WGI_2021_Map") %>%
hc_credits(enabled = FALSE) %>%
hc_tooltip(shared = TRUE,
useHTML = TRUE,
headerFormat = '<table><tr><th, colspan="2">{point.key}</th></tr>',
pointFormat = '<tr><td style="color: {#252223}"><b>{point.country_name}</b><br>Control of Corruption: {point.control_of_corruption}<br>Government Effectiveness: {point.government_effectiveness}<br>Political Stability: {point.political_stability}<br>Regulatory Quality: {point.regulatory_quality}<br>Rule of Law: {point.rule_of_law}<br>Voice and Accountability: {point.voice_and_accountability}<br><b>Mean: {point.value}</b>')
# htmlwidgets::saveWidget(map_df_2021, "WGI_2021.html")
print(df_2021)
## # A tibble: 205 × 9
## # Rowwise:
## country_name count…¹ contr…² gover…³ polit…⁴ regul…⁵ rule_…⁶ voice…⁷ mean
## <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Afghanistan AFG -1.14 -1.63 -2.53 -1.34 -1.87 -1.57 -1.68
## 2 Albania ALB -0.56 0 0.11 0.19 -0.26 0.09 -0.07
## 3 Algeria DZA -0.61 -0.62 -0.88 -1.17 -0.82 -1.01 -0.85
## 4 American Samoa ASM 1.33 0.7 1.05 0.55 1.21 0.91 0.96
## 5 Andorra AND 1.33 1.82 1.63 1.36 1.72 1.04 1.48
## 6 Angola AGO -0.66 -1.06 -0.71 -0.66 -0.95 -0.84 -0.81
## 7 Antigua and Ba… ATG 0.26 -0.14 0.96 0.39 0.34 0.74 0.42
## 8 Argentina ARG -0.4 -0.36 -0.11 -0.62 -0.46 0.62 -0.22
## 9 Armenia ARM 0.07 -0.25 -0.84 0.15 -0.1 0.06 -0.15
## 10 Aruba ABW 0.83 1.13 1.47 0.95 1.28 1.03 1.11
## # … with 195 more rows, and abbreviated variable names ¹country_code,
## # ²control_of_corruption, ³government_effectiveness, ⁴political_stability,
## # ⁵regulatory_quality, ⁶rule_of_law, ⁷voice_and_accountability
Comparison by Continent
The box plot below is based on the 2021 results and demonstrates how a continent is compared to each other within each indicator.
cont_df_2021_plot <- df %>%
filter(year == 2021) %>%
ggplot(aes(x = year, y = value, fill = continent)) +
geom_boxplot(na.rm = T) +
scale_fill_manual(values = c("#3b7f39", "#edbe48", "#52a8b7", "#c23c2b", "#e48223", "#39bd4b")) +
coord_flip() +
facet_wrap(~indicator_name, scales = "free") +
# geom_hline(yintercept =-2, linetype = "dotted", size = .7, color = "black") +
# geom_hline(yintercept = -1, linetype = "dotted", size = .7, color = "black") +
geom_hline(yintercept = 0, linetype = "dotted", size = .7, color = "black") +
# geom_hline(yintercept = 1, linetype = "dotted", size = .7, color = "black") +
# geom_hline(yintercept = 2, linetype = "dotted", size = .7, color = "black") +
labs(x = element_blank(),
y = element_blank(),
fill = "") +
theme_bw() +
theme(axis.text.y = element_blank(),
axis.text.x = element_text(size = 10),
legend.text = element_text(size = 12),
panel.grid = element_blank(),
# strip.background = element_rect(fill = "#6e2b0e"),
strip.text = element_text(size = 11)) +
guides(fill = guide_legend(reverse = TRUE))
print(cont_df_2021_plot)
Comparison between the top 3 Countries of 2021
The line chart below represents a progression of the top 3 countries of 2021 since 1996. By the way, the calculation of the top 3 countries was based on the average(mean) of the six indicators combined.
top_3_2021 <- df %>%
mutate(value = round(value, 2)) %>%
select(country_name, country_code, indicator_name, year, value) %>%
pivot_wider(names_from = "indicator_name",
values_from = "value") %>%
clean_names() %>%
rowwise() %>%
mutate(mean = mean(c_across(4:9)),
mean = round(mean, 2)) %>%
group_by(year) %>%
arrange(year, desc(mean)) %>%
mutate(rank = row_number()) %>%
ungroup() %>%
filter(year == 2021,
rank <= 3)
top_3_plot <- df %>%
filter(country_name %in% c(top_3_2021$country_name)) %>%
select(Country = country_name,
Code = country_code,
Continent = continent,
Indicator = indicator_name,
Year = year,
Score = value) %>%
mutate(Indicator = case_when(Indicator == "Government Effectiveness" ~ "Effectiveness",
T ~ Indicator)) %>%
ggplot(aes(x = Year, y = Score, color = Country)) +
geom_line(size = .7) +
geom_point(color = "black", size = .5) +
facet_wrap(~Indicator, scales = "free") +
scale_x_continuous(breaks = seq(1995, 2020, 10)) +
scale_colour_brewer(palette = "Dark2") +
labs(title = "",
color = "",
y = element_blank(),
x = element_blank()) +
theme_bw() +
theme(legend.text = element_text(size = 10),
# strip.background = element_rect(fill = "#bcdefc"),
strip.text = element_text(size = 10, color = "black"))
top_3_plotly <- ggplotly(top_3_plot, tooltip = c("Year", "Score")) %>%
config(displaylogo = FALSE,
modeBarButtonsToRemove = c("zoom2d","zoomIn2d", "zoomOut2d",
"select",
"lasso2d",
"pan2d"),
toImageButtonOptions = list(format = "svg",
filename = "North_America_Results"))
# htmlwidgets::saveWidget(top_3_plotly, file = "Top_3_Comparison.html")
print(top_3_2021)
## # A tibble: 3 × 11
## country_…¹ count…² year contr…³ gover…⁴ polit…⁵ regul…⁶ rule_…⁷ voice…⁸ mean
## <chr> <chr> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Finland FIN 2021 2.27 1.96 0.98 1.9 2.06 1.62 1.8
## 2 Denmark DNK 2021 2.37 2 0.95 1.81 1.94 1.56 1.77
## 3 Norway NOR 2021 2.14 1.84 1.1 1.64 1.95 1.75 1.74
## # … with 1 more variable: rank <int>, and abbreviated variable names
## # ¹country_name, ²country_code, ³control_of_corruption,
## # ⁴government_effectiveness, ⁵political_stability, ⁶regulatory_quality,
## # ⁷rule_of_law, ⁸voice_and_accountability
USA progression over time
df_usa <- df %>%
filter(country_code == "USA") %>%
select(country_name:value) %>%
rename(Year = year,
Score = value)
usa_plot <- df_usa %>%
ggplot(aes(Year, Score)) +
geom_point(aes(frame = Year, color = indicator_name)) +
geom_line(aes(color = indicator_name), size = 1, alpha = 0.8) +
theme_bw() +
labs(color = " ") +
# ggtitle("USA Governance Indicators") +
scale_color_viridis_d(option = "turbo") +
# gganimate::transition_reveal(Year) +
# coord_cartesian(clip = 'off') +
theme(axis.title = element_blank(),
legend.text = element_text(size = 12),
plot.title = element_text(size = 18, hjust = .5),
axis.text = element_text(size = 12))
# usa_animation <- animate(usa_plot, fps = 10, width = 600, height = 400)
# anim_save("usa_animation.gif", usa_animation)
usa_plotly <- ggplotly(usa_plot, tooltip = c("Year", "Score")) %>%
animation_opts(1000, ) %>%
animation_button(label = "Animate") %>%
config(displaylogo = FALSE,
modeBarButtonsToRemove = c("zoom2d","zoomIn2d", "zoomOut2d",
"select",
"lasso2d",
"pan2d",
"autoScale"),
toImageButtonOptions = list(format = "svg",
filename = "North_America_Results"))
# htmlwidgets::saveWidget(usa_plotly, "USA_Plotly.html")
print(df_usa)
## # A tibble: 138 × 5
## country_name country_code indicator_name Year Score
## <chr> <chr> <chr> <int> <dbl>
## 1 United States USA Control of Corruption 1996 1.57
## 2 United States USA Government Effectiveness 1996 1.52
## 3 United States USA Political Stability 1996 0.94
## 4 United States USA Regulatory Quality 1996 1.59
## 5 United States USA Rule of Law 1996 1.5
## 6 United States USA Voice and Accountability 1996 1.35
## 7 United States USA Control of Corruption 1998 1.55
## 8 United States USA Government Effectiveness 1998 1.7
## 9 United States USA Political Stability 1998 0.88
## 10 United States USA Regulatory Quality 1998 1.61
## # … with 128 more rows
Conclusion
In conclusion, this was a very satisfying and exciting project, and I learned much from it. It highlighted the six governance indicators which determine how prosperous a country is compared to another and how they have progressed over time.
As this is an open-source project, you are welcome to edit this content and send me a pull request through the GitHub edit button I embedded in the footer of this page. Also, in the comment section, let me know your thoughts on this project and which comparisons and charts you wish you saw. I will be reiterating it and adding more content throughout the time and, of course, always keep it updated with the most recent data.
Thank you!