CO2 emissions (metric tons per capita) :EN.ATM.CO2E.PC [Link]
Forest area (% of land area):AG.LND.FRST.ZS [Link]
Renewable electricity output (% of total electricity output):EG.ELC.RNEW.ZS [Link]
Electricity production from oil, gas and coal sources (% of total):EG.ELC.FOSL.ZS [Link]
Electricity production from nuclear sources (% of total):EG.ELC.NUCL.ZS [Link]
Access to electricity, urban (% of urban population):EG.ELC.ACCS.UR.ZS [Link]
Access to electricity, rural (% of rural population):EG.ELC.ACCS.RU.ZS [Link]
People using at least basic drinking water services, urban (% of urban population):SH.H2O.BASW.UR.ZS [Link]
People using at least basic drinking water services, rural (% of rural population):SH.H2O.BASW.RU.ZS [Link]
People using at least basic sanitation services, urban (% of urban population):SH.STA.BASS.UR.ZS [Link]
People using at least basic sanitation services, rural (% of rural population):SH.STA.BASS.RU.ZS [Link]
GDP (current US$).: NY.GDP.MKTP.CD [Link]
Agriculture, forestry, and fishing, value added (% of GDP):NV.AGR.TOTL.ZS [Link]
14.Agricultural land (% of land area):AG.LND.AGRI.ZS [Link]
Government expenditure on education, total (% of
GDP):SE.XPD.TOTL.GD.ZS [Link]
変数名:ed_exp
School enrollment, primary (% gross):SE.PRM.ENRR [Link]
変数名:primary
School enrollment, secondary (% gross):SE.SEC.ENRR [Link]
変数名:secondary
School enrollment, tertiary (% gross):SE.TER.ENRR [Link]
変数名:tertiary
Mortality rate, under-5 (per 1,000 live births):SH.DYN.MORT [Link]
変数名:under5
Incidence of HIV (% of uninfected population ages
15-49):SH.HIV.INCD.ZS [Link]
変数名:new_hiv
library(tidyverse)
library(WDI)
library(plotly)
library(ggplot2)
The analysis will mainly used the Offical Arican Union (OAU), but has also used a Random Sample (RS).
OAU <- c("Algeria", "Angola", "Benin", "Botswana", "Burkina Faso", "Burundi", "Cameroon", "Cape Verde", "Central African Republic", "Chad", "Comoros", "Congo", "Côte d'Ivoire", "Djibouti", "Egypt", "Equatorial Guinea", "Eritrea", "Eswatini", "Ethiopia", "Gabon", "Gambia", "Ghana", "Guinea", "Guinea-Bissau", "Kenya", "Lesotho", "Liberia", "Libya", "Madagascar", "Malawi", "Mali", "Mauritania", "Mauritius", "Morocco", "Mozambique", "Namibia", "Niger", "Nigeria", "Rwanda", "São Tomé and Príncipe", "Senegal", "Seychelles", "Sierra Leone", "Somalia", "South Africa", "South Sudan", "Sudan", "Tanzania", "Togo", "Tunisia", "Uganda", "Zambia", "Zimbabwe")
RS <- c("Ghana", "Cameroon", "Mozambique", "Niger", "Angola", "Tanzania", "Rwanda", "Guinea-Bissau", "Madagascar","Kenya", "Ethiopia")
REGION <- c("1A", "1W", "4E", "6F", "6N", "6X", "7E", "8S", "A4", "A5",
"A9", "B1", "B2", "B3", "B4", "B6", "B7", "B8", "C4", "C5", "C6",
"C7", "C8", "C9", "D2", "D3", "D4", "D5", "D6", "D7", "EU", "F1",
"F6", "M1", "M2", "N6", "OE", "R6", "S1", "S2", "S3", "S4", "T2",
"T3", "T4", "T5", "T6", "T7", "V1", "V2", "V3", "V4", "XC", "XD",
"XE", "XF", "XG", "XH", "XI", "XJ", "XL", "XM", "XN", "XO", "XP",
"XQ", "XT", "XU", "XY", "Z4", "Z7", "ZB", "ZF", "ZG", "ZH", "ZI",
"ZJ", "ZQ", "ZT")
df_environment |> drop_na(agricultureOutput) |> filter(country %in% c(RS, "World")) |> filter(year %in% 1990:2022) |>
ggplot(aes(year, agricultureOutput, col = country)) + geom_line() + facet_wrap(~ country, scales = "free_y") + labs(title = "Agriculture Output (%GDP) in RS and World")
Agriculture Output (% of GDP) of a Random Sample of African Countries and the World Average
While it does seem that most countries are seeing a reduction in their overall agriculture output (possibily due to other sectors, such as mining, becoming more prominent), looking at the y-axsis, all countries still heavily rely on agriculture compared to the world average.
This was briefly mentioned in the report, but Angola seems to have the lowest among all African countries, which could be due to its strong preicous metals sector. However, it has seen a sharp increase since the 2010s, which could again hint at the prevalence of agriculture.
df_service2 |> filter(year == 2022) |> drop_na(agricultureOutput) |>
filter(!(iso2c %in% REGION))|>
arrange(desc(agricultureOutput)) |> head(20) |>
ggplot(aes(fct_reorder(country, agricultureOutput), agricultureOutput)) + geom_col() +
coord_flip() + labs(title = "Top 20 Countries in Agriculture (% of GDP)", x = "country", y = "Agriculture (% of GDP)")
A Ranking of the countries that have the biggest share of Agriculture as their GDP
df_service2 |> filter(country %in% OAU) |>
drop_na(electricity_urban, electricity_rural, water_urban, water_rural, sanitation_urban, sanitation_rural, under_6.85) |>
select(electricity_urban, electricity_rural, water_urban, water_rural, sanitation_urban, sanitation_rural, under_6.85) |> cor() |> round(digits = 2) |> as.data.frame()
df_service2 |> drop_na(water_rural, sanitation_rural) |>
ggplot(aes(water_rural, sanitation_urban)) + geom_point() +
geom_smooth(formula = 'y~x', method = "lm", se = FALSE) +
labs(title = "Correlation of water_rural & sanitation_rural")
df_service2 |> filter(country %in% OAU) |>
drop_na(military_usd:education_gov,electricity_urban:tertiary) |>
select(military_usd:education_gov,electricity_urban:tertiary) |> cor()
military_usd military_gov education_gov electricity_urban
military_usd 1.00000000 0.2736983 -0.091237869 0.11714370
military_gov 0.27369825 1.0000000 -0.404994165 -0.37353959
education_gov -0.09123787 -0.4049942 1.000000000 0.49282161
electricity_urban 0.11714370 -0.3735396 0.492821609 1.00000000
electricity_rural 0.31122795 -0.2881025 0.295144053 0.70583910
water_urban 0.13293605 -0.4586225 0.441162100 0.67948959
water_rural 0.17731597 -0.3557442 0.165875046 0.57102284
sanitation_urban 0.22580305 -0.1514608 0.144984483 0.60186279
sanitation_rural 0.18667671 -0.3045148 0.021242824 0.50594512
agriculture 0.30676785 -0.1092683 -0.112727045 -0.04736146
agricultureOutput -0.26161269 0.2732373 0.008064064 -0.50210848
under_6.85 -0.18736607 0.2083550 -0.165630577 -0.65117804
ed_exp 0.04942884 -0.4299927 0.670990184 0.36386578
primary -0.09590555 -0.3475881 -0.118921917 -0.11088938
secondary 0.40249969 -0.3236322 0.216241949 0.66093207
tertiary 0.19108335 -0.2490551 0.223855377 0.68080446
electricity_rural water_urban water_rural sanitation_urban
military_usd 0.311227953 0.13293605 0.17731597 0.22580305
military_gov -0.288102535 -0.45862249 -0.35574423 -0.15146084
education_gov 0.295144053 0.44116210 0.16587505 0.14498448
electricity_urban 0.705839101 0.67948959 0.57102284 0.60186279
electricity_rural 1.000000000 0.79590537 0.84640734 0.80112011
water_urban 0.795905369 1.00000000 0.81414435 0.70900242
water_rural 0.846407343 0.81414435 1.00000000 0.72352566
sanitation_urban 0.801120105 0.70900242 0.72352566 1.00000000
sanitation_rural 0.764458011 0.65169615 0.79757098 0.85670484
agriculture 0.189935216 0.14273662 0.22217178 0.13417952
agricultureOutput -0.732569325 -0.65884991 -0.69312625 -0.73556029
under_6.85 -0.933941382 -0.70451103 -0.83503330 -0.82395061
ed_exp 0.304243427 0.50662869 0.35530543 0.26242241
primary -0.008336481 -0.05673833 0.08126331 0.05257493
secondary 0.892524314 0.74987038 0.86963003 0.70908264
tertiary 0.899904600 0.63716546 0.80012205 0.76289278
sanitation_rural agriculture agricultureOutput under_6.85 ed_exp
military_usd 0.18667671 0.30676785 -0.261612691 -0.18736607 0.04942884
military_gov -0.30451480 -0.10926828 0.273237251 0.20835505 -0.42999266
education_gov 0.02124282 -0.11272704 0.008064064 -0.16563058 0.67099018
electricity_urban 0.50594512 -0.04736146 -0.502108481 -0.65117804 0.36386578
electricity_rural 0.76445801 0.18993522 -0.732569325 -0.93394138 0.30424343
water_urban 0.65169615 0.14273662 -0.658849908 -0.70451103 0.50662869
water_rural 0.79757098 0.22217178 -0.693126246 -0.83503330 0.35530543
sanitation_urban 0.85670484 0.13417952 -0.735560293 -0.82395061 0.26242241
sanitation_rural 1.00000000 0.37439924 -0.648800378 -0.79565597 0.26299910
agriculture 0.37439924 1.00000000 -0.221811808 -0.07235199 0.29834901
agricultureOutput -0.64880038 -0.22181181 1.000000000 0.72260811 -0.20273140
under_6.85 -0.79565597 -0.07235199 0.722608112 1.00000000 -0.23673528
ed_exp 0.26299910 0.29834901 -0.202731402 -0.23673528 1.00000000
primary 0.28050182 0.54394814 -0.165584298 0.01009416 0.11168668
secondary 0.72122175 0.24925806 -0.765507513 -0.85016555 0.39884714
tertiary 0.75135441 0.09531449 -0.679834033 -0.93558458 0.26351634
primary secondary tertiary
military_usd -0.095905546 0.4024997 0.19108335
military_gov -0.347588077 -0.3236322 -0.24905505
education_gov -0.118921917 0.2162419 0.22385538
electricity_urban -0.110889376 0.6609321 0.68080446
electricity_rural -0.008336481 0.8925243 0.89990460
water_urban -0.056738331 0.7498704 0.63716546
water_rural 0.081263306 0.8696300 0.80012205
sanitation_urban 0.052574931 0.7090826 0.76289278
sanitation_rural 0.280501821 0.7212218 0.75135441
agriculture 0.543948142 0.2492581 0.09531449
agricultureOutput -0.165584298 -0.7655075 -0.67983403
under_6.85 0.010094164 -0.8501655 -0.93558458
ed_exp 0.111686682 0.3988471 0.26351634
primary 1.000000000 0.1701086 0.04294838
secondary 0.170108593 1.0000000 0.86774627
tertiary 0.042948375 0.8677463 1.00000000
A Table showing Correlation between Clean Water and Electricity Accessibility, Sanitation and Poverty Rate (under $6.85)
Although not the strongest correlation, it seems that the essential resources can heavily impact health and safety levels.
The other two figures are unused for the report, but was used as reference and additional information, as I was interested in them. The middle one was simply a correlation graph between water_rural and sanitation_rural, and the bottom is a correlation table of all indicators in the variable. Moreover, I found out that the correlations can change depending on what indicators are included in the analysis; for example, the water_rural/sanitation_rural had a correlation of 0.79. I was slightly confused as to why, so I did not include it in the report.
df_environment |> drop_na(co2pcap) |> filter(country %in% c("World")) |>
ggplot(aes(year, co2pcap, col = country)) + geom_line(show.legend = FALSE) + facet_wrap(~ country, scales = "free_y") + labs(title = "CO2 Emissions (1990-2020)")
CO2 Emissions produced by the whole world between 1990 and 2020.
df_service2 |> filter(country %in% OAU) |> drop_na(water_rural) |>
ggplot(aes(region, water_rural)) + geom_boxplot() + coord_flip() + labs(title = "Box Plot of Water Avaliablity in Rural Areas in OAU countries")
df_service2 |> filter(country %in% OAU) |> drop_na(sanitation_rural) |>
ggplot(aes(region, sanitation_rural)) + geom_boxplot() + coord_flip() + labs(title = "Box Plot of Sanitation Levels in Rural Areas in OAU countries")
Boxplot of Water Avaliabilty and Sanitation levels in Rural areas in the OAU
df_environment |> drop_na(fossil, renewable) |> filter(country == "Brazil") |>
ggplot(aes(year)) + geom_line(aes(y = fossil), color = "red") + geom_line(aes(y = renewable), color = "blue") +
labs(title = "Non-Rewable and Renewable Energy in Japan")
df_environment |> drop_na(fossil, renewable) |> filter(country == "Kenya") |>
ggplot(aes(year)) + geom_line(aes(y = fossil), color = "red") + geom_line(aes(y = renewable), color = "blue") +
labs(title = "Non-Rewable and Renewable Energy in Kenya")
df_serv_long <- df_service2 |>
pivot_longer(cols = c(military_usd:education_gov,electricity_urban:tertiary))
df_serv_long
df_serv_long |> filter(name %in% c("water_rural", "sanitation_rural")) |>
filter(country %in% OAU) |> drop_na(value) |>
ggplot(aes(region, value, fill = name)) + geom_boxplot() + scale_y_log10() + coord_flip()
df_serv_long |> filter(name %in% c("water_urban", "sanitation_urban")) |>
filter(country %in% OAU) |> drop_na(value) |>
ggplot(aes(region, value, fill = name)) + geom_boxplot() + scale_y_log10() + coord_flip()
df_military_ed <- WDI(indicator = c(military_usd = "MS.MIL.XPND.CD",
military_gov = "MS.MIL.XPND.ZS",
education_gov = "SE.XPD.TOTL.GB.ZS"),
extra = TRUE) |>
select(country, iso2c, year, military_usd, military_gov, education_gov, region)
df_military_ed
df_military_ed |> filter(country %in% OAU) |> drop_na(military_usd) |> group_by(year) |>
summarize(avg_military_usd = mean(military_usd, na.rm = TRUE)) |> ggplot(aes(year, avg_military_usd)) + geom_line() +
labs(title = "Average Military Expenditure (USD) Trend in OAU Countries")
df_military_ed |> filter(year == 2010) |> filter(country %in% OAU) |> drop_na(military_gov, education_gov) |>
ggplot(aes(education_gov, military_gov, col = iso2c)) + geom_point() + geom_label(aes(label = iso2c), nudge_y = 0.1) + theme(legend.position = "none") +
labs(title = "Scatterplot of OAU's Education and Military Expenditure in 2010", x = "Education - 教育費(政府の総支出に対する率(%))", y = "Military Expenditure - 軍事費(政府の総支出に対する率(%))")
df_miled_chart <- df_military_ed |> filter(country %in% OAU) |> filter(year == 2010) |> drop_na(military_gov, education_gov) |>
ggplot(aes(education_gov, military_gov, col = iso2c, text = country)) + geom_point() +
labs(title = "Scatterplot of OAU's Education and Military Expenditure in 2010") + theme(legend.position = "none")
df_miled_chart |> ggplotly()
df_military_ed |> filter(year == 2021) |> filter(country %in% OAU) |> drop_na(military_gov, education_gov) |>
ggplot(aes(education_gov, military_gov, col = iso2c)) + geom_point() + geom_label(aes(label = iso2c), nudge_y = 0.1) + theme(legend.position = "none") +
labs(title = "Scatterplot of OAU's Education and Military Expenditure in 2021", x = "Education - 教育費(政府の総支出に対する率(%))", y = "Military Expenditure - 軍事費(政府の総支出に対する率(%))")
df_miled_chart <- df_military_ed |> filter(country %in% OAU) |> filter(year == 2021) |> drop_na(military_gov, education_gov) |>
ggplot(aes(education_gov, military_gov, col = iso2c, text = country)) + geom_point() +
labs(title = "Scatterplot of OAU's Education and Military Expenditure in 2021") + theme(legend.position = "none")
df_miled_chart |> ggplotly()
df_service2 |> filter(country %in% OAU) |>
drop_na(military_usd:education_gov,electricity_urban:tertiary) |>
select(military_usd:education_gov,electricity_urban:tertiary) |> cor()
df_service2 |> filter(country %in% OAU) |>
drop_na(electricity_urban, electricity_rural, water_urban, water_rural, sanitation_urban, sanitation_rural, under_6.85) |>
select(electricity_urban, electricity_rural, water_urban, water_rural, sanitation_urban, sanitation_rural, under_6.85) |> cor() |> round(digits = 2) |> as.data.frame()
df_service2 |> drop_na(water_rural, sanitation_rural) |>
ggplot(aes(water_rural, sanitation_urban)) + geom_point() +
geom_smooth(formula = 'y~x', method = "lm", se = FALSE) +
labs(title = "Correlation of water_rural & sanitation_rural")
df_service2 |> filter(country %in% OAU) |> drop_na(water_urban, water_rural) |> group_by(year) |> summarize(avg_water = mean(c(water_urban, water_rural), na.rm = TRUE)) |>
ggplot(aes(year, avg_water)) + geom_line() +
labs(title = "Average Safe Water Availability in OAU Countries")
df_service2 |> filter(country %in% OAU) |> drop_na(water_urban) |> group_by(year) |> summarize(avg_water1 = mean(c(water_urban), na.rm = TRUE)) |>
ggplot(aes(year, avg_water1)) + geom_line() +
labs(title = "Average Safe Water Availability in OAU Countries (Urban)")
df_service2 |> filter(country %in% OAU) |> drop_na(water_rural) |> group_by(year) |> summarize(avg_water2 = mean(c(water_rural), na.rm = TRUE)) |>
ggplot(aes(year, avg_water2)) + geom_line() +
labs(title = "Average Safe Water Availability Trend in OAU Countries (Rural)")
df_service2 |> filter(country %in% OAU) |> drop_na(electricity_urban, electricity_rural) |> group_by(year) |> summarize(avg_elec = mean(c(electricity_urban, electricity_rural), na.rm = TRUE)) |>
ggplot(aes(year, avg_elec)) + geom_line() +
labs(title = "Average Electricity Availability in OAU Countries")
df_service2 |> filter(country %in% "Ethiopia") |> drop_na(water_urban) |> group_by(year) |>
ggplot(aes(year, water_rural)) + geom_line() +
labs(title = "Average Safe Water Availability in Ethiopia (Rural)")
df_health <- WDI(
indicator = c(electricity_urban = "EG.ELC.ACCS.UR.ZS",
electricity_rural = "EG.ELC.ACCS.RU.ZS",
under_6.85 = "SI.POV.UMIC",
water_urban = "SH.H2O.BASW.UR.ZS",
water_rural = "SH.H2O.BASW.RU.ZS",
sanitation_urban = "SH.STA.BASS.UR.ZS",
sanitation_rural = "SH.STA.BASS.RU.ZS",
health_exp = "SH.XPD.CHEX.GD.ZS",
under5 = "SH.DYN.MORT",
new_hiv = "SH.HIV.INCD.ZS"), extra = TRUE) |>
select(country, iso2c, year, region, electricity_urban, electricity_rural, water_urban, water_rural, sanitation_urban, sanitation_rural,under_6.85, health_exp, under5, new_hiv)
df_health
df_health |> filter(country %in% OAU) |> drop_na(health_exp) |> group_by(year) |> summarize(HealthExp = mean(c(health_exp), na.rm = TRUE)) |>
ggplot(aes(year, HealthExp)) + geom_line() +
labs(title = "Health Expenditure in OAU Countries")
df_poverty_Cliinequality <- WDI(
indicator = c(gini = "SI.POV.GINI",
under_6.85 = "SI.POV.UMIC",
ed_exp = "SE.XPD.TOTL.GD.ZS",
primary = "SE.PRM.ENRR",
co2pcap = "EN.ATM.CO2E.PC",
forest = "AG.LND.FRST.ZS",
secondary = "SE.SEC.ENRR",
tertiary = "SE.TER.ENRR",
under5 = "SH.DYN.MORT",
new_hiv = "SH.HIV.INCD.ZS",
school_gpi = "SE.ENR.PRSC.FM.ZS",
job_gpi = "SL.TLF.CACT.FM.ZS",
female_unemploy = "SL.UEM.TOTL.FE.ZS",
male_unemploy = "SL.UEM.TOTL.FE.ZS",
oda = "DT.ODA.ALLD.CD"), extra = TRUE)
df_poverty_Cliinequality
df_pov_ineq <- df_poverty_Cliinequality |>
select(country, iso2c, year, gini:oda, region, income, lending)
df_pov_ineq
df_pov_ineq |> filter(country %in% RS) |> filter(year == 2017) |> lm(co2pcap ~ under_6.85 + male_unemploy, data = _) |> summary()
df_pov_ineq |> filter(!(iso2c %in% REGION)) |> filter(year == 2017) |> lm(co2pcap ~ under_6.85 + male_unemploy, data = _) |> summary()