IGAD, a prominent economic consortium in East Africa, spans across 5.2 million square kilometers, covering Djibouti, Eritrea, Ethiopia, Kenya, Somalia, South Sudan, Sudan, and Uganda.
2024-06-01
IGAD, a prominent economic consortium in East Africa, spans across 5.2 million square kilometers, covering Djibouti, Eritrea, Ethiopia, Kenya, Somalia, South Sudan, Sudan, and Uganda.
We’ll visualize some key profiles of the countries within IGAD, including their population, population density (people per square kilometer), and the percentage of urban population.
Data for African countries, including population, density, urban population percentage, and other classifications, can be accessed from this site. The corresponding CSV file provided in 2024, though containing data from 2023, is available here.
library(plotly)
library(tidyr)
library(tidyverse)
population<-read.csv(
"https://raw.githubusercontent.com/dawit3000/Data/main/population_africa_2024.csv")
IGAD<-filter(population, population[,2] %in% c("Djibouti", "Eritrea",
"Ethiopia", "Kenya", "Somalia", "South Sudan", "Sudan", "Uganda") )
IGAD<-IGAD[, c(2,3,6,11)]
show(IGAD)
## Country Population Density Urban ## 1 Ethiopia 126,527,060 127 22% ## 2 Kenya 55,100,586 97 31% ## 3 Sudan 48,109,006 27 35% ## 4 Uganda 48,582,334 243 29% ## 5 Somalia 18,143,378 29 46% ## 6 South Sudan 11,088,796 18 28% ## 7 Eritrea 3,748,901 37 67% ## 8 Djibouti 1,136,455 49 72%
We will create new variables for the following
IGAD$Population<-as.numeric(gsub(",", "", IGAD$Population))
IGAD$PCT_Population<-round((IGAD$Population)*(100/sum(IGAD$Population)),0)
IGAD$Density<-as.numeric(gsub(",", "", IGAD$Density))
IGAD$PCT_Density<-round((IGAD$Density)*(100/sum(IGAD$Density)),0)
IGAD$PCT_Urban<-as.numeric(gsub("[\\%,]","", IGAD$Urban))
IGAD<-IGAD[, c(-4)]
show(IGAD)
## Country Population Density PCT_Population PCT_Density PCT_Urban ## 1 Ethiopia 126527060 127 40 20 22 ## 2 Kenya 55100586 97 18 15 31 ## 3 Sudan 48109006 27 15 4 35 ## 4 Uganda 48582334 243 16 39 29 ## 5 Somalia 18143378 29 6 5 46 ## 6 South Sudan 11088796 18 4 3 28 ## 7 Eritrea 3748901 37 1 6 67 ## 8 Djibouti 1136455 49 0 8 72
We use the three new variables and pass it to “plot_ly” to plot bar-graph.
myplot<-plot_ly(IGAD, x = ~Country, y = ~PCT_Population,
type = "bar", name = "% Population within IGAD") %>%
add_trace(y = ~PCT_Density, type = "bar",
name = "% Density withing border") %>%
add_trace(y = ~PCT_Urban, type = "bar",
name = "% Urban pop. within border") %>%
layout(title = "IGAD: Key Profiles",
xaxis=list(title = "IGAD Country", tickangle = -45),
yaxis =list(title = "Percentage"), margin= list(b=100),
barmode = "group")
myplot