Research Question

How is the world population distributed across World Bank income groups in 2024, and how many countries are in each income group?

Import the Data

SPI_data <- read_csv("Downloads/SPI_data.csv")
## Rows: 4557 Columns: 117
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (47): iso3c, RAW.D2.1.GDDS, RAW.D2.4.NADA_text, RAW.D4.1.1.POPU, RAW.D4....
## dbl (70): date, SPI.D1.5.POV, SPI.D1.5.CHLD.MORT, SPI.D1.5.DT.TDS.DPPF.XP.ZS...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(SPI_data)
## # A tibble: 6 × 117
##   iso3c  date SPI.D1.5.POV SPI.D1.5.CHLD.MORT SPI.D1.5.DT.TDS.DPPF.XP.ZS
##   <chr> <dbl>        <dbl>              <dbl>                      <dbl>
## 1 AFG    2004            0                  1                          0
## 2 AFG    2005            0                  1                          0
## 3 AFG    2006            0                  1                          0
## 4 AFG    2007            0                  1                          0
## 5 AFG    2008            0                  1                          0
## 6 AFG    2009            0                  1                          0
## # ℹ 112 more variables: SPI.D1.5.SAFE.MAN.WATER <dbl>, SPI.D1.5.LFP <dbl>,
## #   SPI.D2.1.GDDS <dbl>, SPI.D2.2.Machine.readable <dbl>,
## #   SPI.D2.2.Non.proprietary <dbl>, SPI.D2.2.Download.options <dbl>,
## #   SPI.D2.2.Metadata.available <dbl>, SPI.D2.2.Terms.of.use <dbl>,
## #   SPI.D2.2.Openness.subscore <dbl>, SPI.D2.4.NADA <dbl>, SPI.D3.1.POV <dbl>,
## #   SPI.D3.2.HNGR <dbl>, SPI.D3.3.HLTH <dbl>, SPI.D3.4.EDUC <dbl>,
## #   SPI.D3.5.GEND <dbl>, SPI.D3.6.WTRS <dbl>, SPI.D3.7.ENRG <dbl>, …

Prepare the Data

SPI_2024 <- SPI_data %>%
  filter(date == 2024,
         income_level != "Not classified") %>%
  select(country, region, income_level, population)

head(SPI_2024)
## # A tibble: 6 × 4
##   country        region                                  income_level population
##   <chr>          <chr>                                   <chr>             <dbl>
## 1 Afghanistan    Middle East, North Africa, Afghanistan… Low income     42647492
## 2 Albania        Europe & Central Asia                   Upper middl…    2714617
## 3 Algeria        Middle East, North Africa, Afghanistan… Upper middl…   46814308
## 4 American Samoa East Asia & Pacific                     High income       46765
## 5 Andorra        Europe & Central Asia                   High income       81938
## 6 Angola         Sub-Saharan Africa                      Lower middl…   37885849

Check for Missing Values

colSums(is.na(SPI_2024))
##      country       region income_level   population 
##            0            0            0            0

Insight 1: Number of Countries in Each Income Group

country_counts <- SPI_2024 %>%
  count(income_level, name = "Number_of_Countries") %>%
  arrange(desc(Number_of_Countries))

country_counts
## # A tibble: 4 × 2
##   income_level        Number_of_Countries
##   <chr>                             <int>
## 1 High income                          86
## 2 Upper middle income                  54
## 3 Lower middle income                  50
## 4 Low income                           25

The results show how many countries are included in each World Bank income group in 2024. This makes it easier to compare the size of each category based on the number of countries.

Insight 2: Population by Income Group

population_summary <- SPI_2024 %>%
  group_by(income_level) %>%
  summarize(
    Total_Population = sum(population, na.rm = TRUE),
    Average_Population = mean(population, na.rm = TRUE)
  ) %>%
  arrange(desc(Total_Population))

population_summary
## # A tibble: 4 × 3
##   income_level        Total_Population Average_Population
##   <chr>                          <dbl>              <dbl>
## 1 Lower middle income       3120983658          62419673.
## 2 Upper middle income       2818128105          52187558.
## 3 High income               1394458376          16214632.
## 4 Low income                 624608098          24984324.

The results show that the income group with the most countries is not necessarily the group with the largest total population. This shows why it is useful to compare both the number of countries and the population represented by each income group.

Visualization

population_summary <- population_summary %>%
  mutate(
    Total_Population_Billions = Total_Population / 1000000000
  )

ggplot(population_summary,
       aes(x = reorder(income_level, Total_Population_Billions),
           y = Total_Population_Billions)) +
  geom_col() +
  coord_flip() +
  labs(
    title = "Population by World Bank Income Group in 2024",
    x = "Income Group",
    y = "Total Population (Billions)"
  )

Conclusion

This analysis compares World Bank income groups based on both the number of countries and their total population. The results show that the largest income category by number of countries is not necessarily the category with the greatest population. Using group_by(), summarize(), count(), and ggplot() made it easier to organize the data and identify these differences.