library(dplyr)
library(ggplot2)

gdp <- readr::read_csv("gdp_data.csv")

head(gdp)
## # A tibble: 6 × 4
##   Code  Ranking Economy             GDP
##   <chr>   <dbl> <chr>             <dbl>
## 1 USA         1 United States  30769700
## 2 CHN         2 China          19498039
## 3 DEU         3 Germany         5050923
## 4 JPN         4 Japan           4435163
## 5 GBR         5 United Kingdom  4002588
## 6 IND         6 India           3956067
gdp <- gdp %>%
  mutate(Group = ifelse(Ranking <= 5, "Top 5", "Other 199"))

Insight 1

total_gdp <- sum(gdp$GDP)

insight1 <- gdp %>%
  group_by(Group) %>%
  summarize(Total_GDP = sum(GDP),
            Percent_of_Total = (sum(GDP) / total_gdp) * 100)

insight1
## # A tibble: 2 × 3
##   Group     Total_GDP Percent_of_Total
##   <chr>         <dbl>            <dbl>
## 1 Other 199  53391567             45.6
## 2 Top 5      63756413             54.4
gdp %>% count(Group)
## # A tibble: 2 × 2
##   Group         n
##   <chr>     <int>
## 1 Other 199   199
## 2 Top 5         5

The Top 5 countries (United States, China, Germany, Japan, and United Kingdom) make up only 2.5% of the 204 countries by count, but they account for 54.4% of the combined GDP, more than the remaining 199 countries combined (45.6%).

Insight 2

insight2 <- gdp %>%
  filter(Ranking <= 5) %>%
  group_by(Economy) %>%
  summarize(GDP = sum(GDP),
            Percent_of_Total = (sum(GDP) / total_gdp) * 100) %>%
  arrange(desc(GDP))

insight2
## # A tibble: 5 × 3
##   Economy             GDP Percent_of_Total
##   <chr>             <dbl>            <dbl>
## 1 United States  30769700            26.3 
## 2 China          19498039            16.6 
## 3 Germany         5050923             4.31
## 4 Japan           4435163             3.79
## 5 United Kingdom  4002588             3.42

There is a large gap within the Top 5 as well. The United States alone accounts for about 26.3% of the combined GDP of all 204 countries, roughly 1.6 times China’s share (about 16.6%).

Visualization

ggplot(data = insight1, mapping = aes(x = Group, y = Total_GDP)) +
  geom_bar(stat = "identity") +
  labs(title = "Top 5 vs Other 199 Countries: Total GDP (2025)",
       x = "Group",
       y = "Total GDP (millions of US dollars)")