Introduction

This analysis examines global population trends spanning from 1980 to 2050, focusing on changes in population density and distribution across various countries. By using interactive visualizations, we can observe regional population growth patterns and shifts in demographic landscapes over time.

Data Overview

# Load the dataset
Countries_Data <- read.csv("C:/Users/user/Downloads/countries-table.csv")

# Display basic dataset information
dim(Countries_Data)         # Shape of the dataset
## [1] 234  20
colnames(Countries_Data)    # Column names
##  [1] "place"           "pop1980"         "pop2000"         "pop2010"        
##  [5] "pop2023"         "pop2024"         "pop2030"         "pop2050"        
##  [9] "country"         "area"            "landAreaKm"      "cca2"           
## [13] "cca3"            "unMember"        "netChange"       "growthRate"     
## [17] "worldPercentage" "density"         "densityMi"       "rank"
head(Countries_Data)        # First few rows
##   place   pop1980    pop2000    pop2010    pop2023    pop2024    pop2030
## 1   356 687354000 1057920000 1243480000 1438070000 1450940000 1525140000
## 2   156 983164000 1269580000 1351560000 1422580000 1419320000 1398150000
## 3   840 229859000  281484000  311063000  343477000  345427000  355650000
## 4   360 148951000  216078000  246305000  281190000  283488000  295877000
## 5   586  82291000  154879000  199239000  247504000  251269000  276883000
## 6   566  73764600  126382000  166643000  227883000  232679000  262381000
##      pop2050       country    area landAreaKm cca2 cca3 unMember netChange
## 1 1679590000         India 3287590    2973190   IN  IND     true    0.4119
## 2 1260290000         China 9706961    9424703   CN  CHN     true   -0.1006
## 3  380847000 United States 9372610    9147420   US  USA     true    0.0600
## 4  320713000     Indonesia 1904569    1877519   ID  IDN     true    0.0719
## 5  371864000      Pakistan  881912     770880   PK  PAK     true    0.1225
## 6  359186000       Nigeria  923768     910770   NG  NGA     true    0.1526
##   growthRate worldPercentage  density densityMi rank
## 1     0.0089          0.1813 488.0078 1263.9403    1
## 2    -0.0023          0.1773 150.5957  390.0429    2
## 3     0.0057          0.0432  37.7622   97.8042    3
## 4     0.0082          0.0354 150.9907  391.0660    4
## 5     0.0152          0.0314 325.9509  844.2127    5
## 6     0.0210          0.0291 255.4750  661.6803    6
str(Countries_Data)         # Structure of dataset
## 'data.frame':    234 obs. of  20 variables:
##  $ place          : int  356 156 840 360 586 566 76 50 643 231 ...
##  $ pop1980        : int  687354000 983164000 229859000 148951000 82291000 73764600 121207000 88016400 138573000 34428500 ...
##  $ pop2000        : int  1057920000 1269580000 281484000 216078000 154879000 126382000 174018000 134544000 146718000 67411500 ...
##  $ pop2010        : int  1243480000 1351560000 311063000 246305000 199239000 166643000 193702000 152202000 143934000 90538500 ...
##  $ pop2023        : int  1438070000 1422580000 343477000 281190000 247504000 227883000 211141000 171467000 145440000 128692000 ...
##  $ pop2024        : int  1450940000 1419320000 345427000 283488000 251269000 232679000 211999000 173562000 144820000 132060000 ...
##  $ pop2030        : int  1525140000 1398150000 355650000 295877000 276883000 262381000 216074000 186072000 141889000 152855000 ...
##  $ pop2050        : int  1679590000 1260290000 380847000 320713000 371864000 359186000 217489000 214709000 136133000 225022000 ...
##  $ country        : chr  "India" "China" "United States" "Indonesia" ...
##  $ area           : num  3287590 9706961 9372610 1904569 881912 ...
##  $ landAreaKm     : num  2973190 9424703 9147420 1877519 770880 ...
##  $ cca2           : chr  "IN" "CN" "US" "ID" ...
##  $ cca3           : chr  "IND" "CHN" "USA" "IDN" ...
##  $ unMember       : chr  "true" "true" "true" "true" ...
##  $ netChange      : num  0.4119 -0.1006 0.06 0.0719 0.1225 ...
##  $ growthRate     : num  0.0089 -0.0023 0.0057 0.0082 0.0152 0.021 0.0041 0.0122 -0.0043 0.0262 ...
##  $ worldPercentage: num  0.1813 0.1773 0.0432 0.0354 0.0314 ...
##  $ density        : num  488 150.6 37.8 151 326 ...
##  $ densityMi      : num  1263.9 390 97.8 391.1 844.2 ...
##  $ rank           : int  1 2 3 4 5 6 7 8 9 10 ...
summary(Countries_Data) 
##      place          pop1980             pop2000             pop2010         
##  Min.   :  4.0   Min.   :      743   Min.   :6.910e+02   Min.   :6.210e+02  
##  1st Qu.:223.0   1st Qu.:   233928   1st Qu.:3.245e+05   1st Qu.:3.936e+05  
##  Median :439.0   Median :  3180005   Median :4.327e+06   Median :4.965e+06  
##  Mean   :439.1   Mean   : 18999934   Mean   :2.637e+07   Mean   :3.000e+07  
##  3rd Qu.:659.8   3rd Qu.:  9794505   3rd Qu.:1.592e+07   3rd Qu.:1.905e+07  
##  Max.   :894.0   Max.   :983164000   Max.   :1.270e+09   Max.   :1.352e+09  
##                                                                             
##     pop2023             pop2024             pop2030         
##  Min.   :4.960e+02   Min.   :4.960e+02   Min.   :5.280e+02  
##  1st Qu.:4.231e+05   1st Qu.:4.285e+05   1st Qu.:4.580e+05  
##  Median :5.560e+06   Median :5.615e+06   Median :6.108e+06  
##  Mean   :3.457e+07   Mean   :3.487e+07   Mean   :3.661e+07  
##  3rd Qu.:2.324e+07   3rd Qu.:2.347e+07   3rd Qu.:2.634e+07  
##  Max.   :1.438e+09   Max.   :1.451e+09   Max.   :1.525e+09  
##                                                             
##     pop2050            country               area            landAreaKm      
##  Min.   :7.140e+02   Length:234         Min.   :       0   Min.   :       0  
##  1st Qu.:5.336e+05   Class :character   1st Qu.:    2650   1st Qu.:    2626  
##  Median :6.246e+06   Mode  :character   Median :   81200   Median :   75689  
##  Mean   :4.129e+07                      Mean   :  581450   Mean   :  557112  
##  3rd Qu.:3.274e+07                      3rd Qu.:  430426   3rd Qu.:  404788  
##  Max.   :1.680e+09                      Max.   :17098242   Max.   :16376870  
##                                                                              
##      cca2               cca3             unMember           netChange       
##  Length:234         Length:234         Length:234         Min.   :-0.10060  
##  Class :character   Class :character   Class :character   1st Qu.: 0.00000  
##  Mode  :character   Mode  :character   Mode  :character   Median : 0.00080  
##                                                           Mean   : 0.00969  
##                                                           3rd Qu.: 0.00780  
##                                                           Max.   : 0.41190  
##                                                           NA's   :5         
##    growthRate        worldPercentage      density            densityMi       
##  Min.   :-0.050400   Min.   :0.00000   Min.   :    0.136   Min.   :    0.35  
##  1st Qu.: 0.000150   1st Qu.:0.00010   1st Qu.:   40.205   1st Qu.:  104.13  
##  Median : 0.008550   Median :0.00070   Median :   99.540   Median :  257.81  
##  Mean   : 0.009386   Mean   :0.00447   Mean   :  461.813   Mean   : 1196.10  
##  3rd Qu.: 0.018450   3rd Qu.:0.00310   3rd Qu.:  257.361   3rd Qu.:  666.57  
##  Max.   : 0.050700   Max.   :0.18130   Max.   :21892.462   Max.   :56701.48  
##                      NA's   :6                                               
##       rank       
##  Min.   :  1.00  
##  1st Qu.: 59.25  
##  Median :117.50  
##  Mean   :117.50  
##  3rd Qu.:175.75  
##  Max.   :234.00  
## 
# Check for missing values in each column
colSums(is.na(Countries_Data))
##           place         pop1980         pop2000         pop2010         pop2023 
##               0               0               0               0               0 
##         pop2024         pop2030         pop2050         country            area 
##               0               0               0               0               0 
##      landAreaKm            cca2            cca3        unMember       netChange 
##               0               1               0               0               5 
##      growthRate worldPercentage         density       densityMi            rank 
##               0               6               0               0               0
# Replace missing values where necessary
Countries_Data$cca2[is.na(Countries_Data$cca2)] <- "IN" 
Countries_Data$netChange[is.na(Countries_Data$netChange)] <- median(Countries_Data$netChange, na.rm = TRUE)
Countries_Data$worldPercentage[is.na(Countries_Data$worldPercentage)] <- median(Countries_Data$worldPercentage, na.rm = TRUE)

# Check the number of duplicate rows
sum(duplicated(Countries_Data))
## [1] 0
# Count the number of unique values in each column
sapply(Countries_Data, n_distinct)
##           place         pop1980         pop2000         pop2010         pop2023 
##             234             234             234             234             234 
##         pop2024         pop2030         pop2050         country            area 
##             234             234             234             234             232 
##      landAreaKm            cca2            cca3        unMember       netChange 
##             230             233             234               2             121 
##      growthRate worldPercentage         density       densityMi            rank 
##             181              75             234             234             234

Data Visualization

Visualize UN Membership Distribution The pie chart shows that we have more countries under UN membership.

unMember_counts <- Countries_Data %>%
  group_by(unMember) %>%
  summarise(count = n())

unMember_counts$label <- ifelse(unMember_counts$unMember, "Is UN Member", "Is Not UN Member")

ggplot(unMember_counts, aes(x = "", y = count, fill = label)) +
  geom_bar(stat = "identity", width = 1) +
  coord_polar("y") +
  labs(title = "Overall Distribution of Countries by UN Membership", fill = "UN Membership") +
  theme_minimal() +
  theme(axis.title.x = element_blank(), axis.title.y = element_blank()) +
  geom_text(aes(label = scales::percent(count / sum(count), accuracy = 0.1)),
            position = position_stack(vjust = 0.5)) +
  scale_fill_manual(values = c("purple", "yellow"))

Maps

World Population in 1980

This analysis reveals that China, India, the United States, Indonesia, and Russia had the highest populations in 1980, while the least populated areas included Vatican City, Tokelau, the Falkland Islands, Saint Barthelemy, and Niue..

# Load and merge with world map data
world <- ne_countries(scale = "medium", returnclass = "sf")
world <- world %>%
  left_join(Countries_Data, by = c("iso_a3" = "cca3"))

# Map Population in 1980 (static map)
ggplot(world) +
  geom_sf(aes(fill = pop1980)) +
  scale_fill_gradientn(colors = c("yellow", "orange", "red"), na.value = "gray90", name = "Population 1980") +
  labs(title = "World Population in 1980") +
  theme_minimal() +
  theme(
    legend.position = c(0.08, 0.03),
    legend.title = element_text(size = 6),
    legend.text = element_text(size = 6),
    legend.background = element_rect(fill = "white", color = "black"),
    plot.title = element_text(size = 16, hjust = 0.5)
  ) 
## Warning: A numeric `legend.position` argument in `theme()` was deprecated in ggplot2
## 3.5.0.
## ℹ Please use the `legend.position.inside` argument of `theme()` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

Interactive map : This plot is made interactive for people to be able to know the highest and the lowest populated country just by clicking on the map.

# Interactive map
p <- ggplot(world) +
  geom_sf(aes(fill = pop1980, text = paste("Country:", country, "<br>Population 1980:", pop1980))) +
  scale_fill_gradientn(
    colors = c("yellow", "orange", "red"),
    na.value = "gray90",
    name = "Population 1980"
  ) +
  labs(title = "World Population in 1980") +
  theme_minimal() +
  theme(
    legend.position = c(0.08, 0.03),
    legend.title = element_text(size = 6),
    legend.text = element_text(size = 6),
    legend.background = element_rect(fill = "white", color = "black"),
    plot.title = element_text(size = 16, hjust = 0.5)
  )
## Warning in layer_sf(geom = GeomSf, data = data, mapping = mapping, stat = stat,
## : Ignoring unknown aesthetics: text
interactive_map <- ggplotly(p, tooltip = "text")

# Display the interactive map
interactive_map

World Population in 2000

From this map, we observed that Russia, which was among the top five most populated countries in 1980, was replaced by Brazil in the rankings according to our data set. Additionally, Montserrat replaced Saint Barthelemy in the lower population rankings..

# Map Population in 2000 with enhanced legend and color scheme
ggplot(data = world) +
  geom_sf(color = "black", fill = NA) +
  geom_sf(aes(fill = pop2000)) +
  scale_fill_viridis_c(name = "Population 2000", option = "YlOrRd",
                       guide = guide_colorbar(title.position = "top", title.hjust = 0.5,
                                              barwidth = 20, barheight = 1)) +
  labs(title = "World Population in 2000") +
  theme_minimal() +
  theme(
    legend.position = "bottom",
    legend.title = element_text(size = 14),
    legend.text = element_text(size = 12),
    plot.title = element_text(size = 16, face = "bold")
  )
## Warning in viridisLite::viridis(n, alpha, begin, end, direction, option):
## Option 'YlOrRd' does not exist. Defaulting to 'viridis'.

#interactive 

# Create a ggplot object for the map with population data for 2000
d_2000 <- ggplot(data = world) +
  geom_sf(color = "black", fill = NA) +  # Draw boundaries
  geom_sf(aes(fill = pop2000, text = paste("Country:", country, "<br>Population 2000:", pop2000))) +
  scale_fill_viridis_c(
    name = "Population 2000", 
    option = "YlOrRd",
    guide = guide_colorbar(
      title.position = "top",
      title.hjust = 0.5,
      barwidth = 20,
      barheight = 1
    )
  ) +
  labs(title = "World Population in 2000") +
  theme_minimal() +
  theme(
    legend.position = "bottom",
    legend.title = element_text(size = 14),
    legend.text = element_text(size = 12),
    plot.title = element_text(size = 16, face = "bold")
  )
## Warning in layer_sf(geom = GeomSf, data = data, mapping = mapping, stat = stat,
## : Ignoring unknown aesthetics: text
## Warning in viridisLite::viridis(n, alpha, begin, end, direction, option):
## Option 'YlOrRd' does not exist. Defaulting to 'viridis'.
# Convert ggplot to an interactive plotly object with tooltip
interactive_map <- ggplotly(d_2000, tooltip = "text")

# Display the interactive map
interactive_map

World Population in 2010

In 2010, we observed that China, India, the United States, and Indonesia consistently remained the four most populous countries from 1980 to 2010. Pakistan joined the top five, replacing Russia. Additionally, there was a continued decline in the population of Vatican City..

# Update the ggplot code for population in 2010
d_2010 <- ggplot(data = world) +
  geom_sf(color = "black", fill = NA) +  # Draw boundaries
  geom_sf(aes(fill = pop2010, text = paste("Country:", country, "<br>Population 2010:", pop2010))) +  # Use pop2010
  scale_fill_viridis_c(
    name = "Population 2010", 
    option = "YlOrRd",
    guide = guide_colorbar(
      title.position = "top",
      title.hjust = 0.5,
      barwidth = 20,
      barheight = 1
    )
  ) +
  labs(title = "World Population in 2010") +
  theme_minimal() +
  theme(
    legend.position = "bottom",
    legend.title = element_text(size = 14),
    legend.text = element_text(size = 12),
    plot.title = element_text(size = 16, face = "bold")
  )
## Warning in layer_sf(geom = GeomSf, data = data, mapping = mapping, stat = stat,
## : Ignoring unknown aesthetics: text
## Warning in viridisLite::viridis(n, alpha, begin, end, direction, option):
## Option 'YlOrRd' does not exist. Defaulting to 'viridis'.
# Convert ggplot to an interactive plotly object with tooltip
interactive_map_2010 <- ggplotly(d_2010, tooltip = "text")

# Display the interactive map
interactive_map_2010

World Population in 2023

A massive change was noticed that India replaced China after so many years to become the highest populated country in the world,while the top 5 from 2010 still remained the same and Vatican city still remained the least populated.

# Create a map for the world population in 2023
ggplot(world) +
  geom_sf(aes(fill = pop2023)) +  # Use pop2023 for the fill
  scale_fill_gradientn(colors = c("yellow", "orange", "red"), na.value = "gray90", name = "Population 2023") +
  labs(title = "World Population in 2023") +
  theme_minimal() +
  theme(
    legend.position = c(0.08, 0.03),
    legend.title = element_text(size = 6),
    legend.text = element_text(size = 6),
    legend.background = element_rect(fill = "white", color = "black"),
    plot.title = element_text(size = 16, hjust = 0.5)
  )

# Convert to an interactive plotly object
interactive_map_2023 <- ggplotly(ggplot(world) +
                                   geom_sf(aes(fill = pop2023, text = paste("Country:", country, "<br>Population 2023:", pop2023))) + 
                                   scale_fill_gradientn(colors = c("yellow", "orange", "red"), na.value = "green", name = "Population 2023") +
                                   labs(title = "World Population in 2023") +
                                   theme_minimal() +
                                   theme(
                                     legend.position = c(0.08, 0.03),
                                     legend.title = element_text(size = 6),
                                     legend.text = element_text(size = 6),
                                     legend.background = element_rect(fill = "white", color = "black"),
                                     plot.title = element_text(size = 16, hjust = 0.5)
                                   ), tooltip = "text")
## Warning in layer_sf(geom = GeomSf, data = data, mapping = mapping, stat = stat,
## : Ignoring unknown aesthetics: text
# Display the interactive map
interactive_map_2023

World Population in 2024

The top 5 populated Countries and the 5 least populated countries in 2023, remains the same in 2024 but cahnages in population size was observed.

# Create ggplot for population in 2024
d_2024 <- ggplot(world) +
  geom_sf(aes(fill = pop2024, text = paste("Country:", country, "<br>Population 2024:", pop2024))) +  # Add text for tooltips
  scale_fill_gradientn(colors = c("lightblue", "blue", "darkblue"), 
                       na.value = "gray90", 
                       name = "Population 2024") +
  labs(title = "World Population in 2024") +
  theme_minimal() +
  theme(
    legend.position = c(0.08, 0.03),
    legend.title = element_text(size = 6),
    legend.text = element_text(size = 6),
    legend.background = element_rect(fill = "white", color = "black"),
    plot.title = element_text(size = 16, hjust = 0.5)
  )
## Warning in layer_sf(geom = GeomSf, data = data, mapping = mapping, stat = stat,
## : Ignoring unknown aesthetics: text
# Convert ggplot to an interactive plotly object for 2024
interactive_map_2024 <- ggplotly(d_2024, tooltip = "text")

# Display the interactive map for 2024
interactive_map_2024

World Population in 2030

This predicted data set indicates that the top 5 most populous countries are expected to remain the highest in population globally, while the least populated country is also projected to stay the same.

# Create ggplot for population in 2030
d_2030 <- ggplot(world) +
  geom_sf(aes(fill = pop2030, text = paste("Country:", country, "<br>Population 2030:", pop2030))) +  # Add text for tooltips
  scale_fill_gradientn(colors = c("lightgreen", "green", "darkgreen"), 
                       na.value = "gray90", 
                       name = "Population 2030") +
  labs(title = "World Population in 2030") +
  theme_minimal() +
  theme(
    legend.position = c(0.08, 0.03),
    legend.title = element_text(size = 6),
    legend.text = element_text(size = 6),
    legend.background = element_rect(fill = "white", color = "black"),
    plot.title = element_text(size = 16, hjust = 0.5)
  )
## Warning in layer_sf(geom = GeomSf, data = data, mapping = mapping, stat = stat,
## : Ignoring unknown aesthetics: text
# Convert ggplot to an interactive plotly object for 2030
interactive_map_2030 <- ggplotly(d_2030, tooltip = "text")

# Display the interactive map for 2030
interactive_map_2030

World Population in 2050

The data set predicts that Nigeria will join the ranks of the top 5 most populous countries in the world, alongside India, China, the United States, and Pakistan. It also suggests that the least populous country will remain unchanged.

# Create ggplot for population in 2050
d_2050 <- ggplot(world) +
  geom_sf(aes(fill = pop2050, text = paste("Country:", country, "<br>Population 2050:", pop2050))) +  # Add text for tooltips
  scale_fill_gradientn(colors = c("lightcoral", "coral", "darkred"), 
                       na.value = "gray90", 
                       name = "Population 2050") +
  labs(title = "World Population in 2050") +
  theme_minimal() +
  theme(
    legend.position = c(0.08, 0.03),
    legend.title = element_text(size = 6),
    legend.text = element_text(size = 6),
    legend.background = element_rect(fill = "white", color = "black"),
    plot.title = element_text(size = 16, hjust = 0.5)
  )
## Warning in layer_sf(geom = GeomSf, data = data, mapping = mapping, stat = stat,
## : Ignoring unknown aesthetics: text
# Convert ggplot to an interactive plotly object for 2050
interactive_map_2050 <- ggplotly(d_2050, tooltip = "text")

# Display the interactive map for 2050
interactive_map_2050

Distribution of Countries by UN Membership This shows that high numbers of countries belongs to UN Members.

world <- ne_countries(scale = "medium", returnclass = "sf")

# Convert unMember column to numeric in your dataset
Countries_Data$unMember <- as.numeric(factor(Countries_Data$unMember))

# Merge with your own data using the 'iso_a3' column
world <- left_join(world, Countries_Data, by = c("iso_a3" = "cca3"))

# Plot
ggplot(data = world) +
  geom_sf(aes(fill = as.factor(unMember)), color = "black") +
  scale_fill_manual(values = c("1" = "blue", "2" = "lightblue"), 
                    na.value = "grey", name = "UN Membership") +
  labs(title = "Distribution of Countries by UN Membership") +
  theme_minimal() +
  theme(plot.title = element_text(size = 16, face = "bold", hjust = 0.5),
        legend.position = "bottom")

Land Area

This shows the distribution of land area among the countries of the world.

# Calculate area (in km²) and convert to numeric
world$area <- as.numeric(st_area(world)) / 1e6  # Convert from m² to km²

# Define a color palette for area distribution
area_pal <- colorNumeric(palette = "Blues", domain = world$area)

# Create interactive map
leaflet(data = world) %>%
  addTiles() %>%
  addPolygons(
    fillColor = ~area_pal(area),  # Color based on area
    color = "black",               # Country boundaries in black
    weight = 1,                    # Boundary weight
    fillOpacity = 0.7,             # Fill opacity
    label = ~paste0("Country: ", name, 
                    "<br>Area: ", round(area, 2), " km²"), # Tooltip label
    labelOptions = labelOptions(
      style = list("font-weight" = "normal", padding = "3px 8px"),
      textsize = "15px",
      direction = "auto"
    )
  ) %>%
  addLegend("bottomright", 
            pal = area_pal, 
            values = ~area,
            title = "Country Area (km²)",
            labFormat = labelFormat(prefix = "")) %>%
  setView(lng = 0, lat = 20, zoom = 2)  
# Download Natural Earth low-resolution countries data with ISO codes
world <- ne_countries(scale = "medium", returnclass = "sf")

# Example definition of your dataset df (replace with your actual data)
df <- data.frame(
  cca3 = c("USA", "CAN", "MEX", "GBR", "AUS"),  # Example country codes
  landAreaKm = c(9372610, 9984670, 1964375, 243610, 7692024)  # Example land areas in km²
)

# Merge world data with your dataset
world <- left_join(world, Countries_Data, by = c("iso_a3" = "cca3"))

# Check for NAs after merge
if (any(is.na(world$landAreaKm))) {
  warning("There are NA values in 'landAreaKm'. Check your merge and data.")
}
## Warning: There are NA values in 'landAreaKm'. Check your merge and data.
# Define a color palette for land area distribution
pal <- colorNumeric(palette = "Reds", domain = world$landAreaKm)

# Create interactive map
leaflet(data = world) %>%
  addTiles() %>%  # Add default OpenStreetMap tiles
  addPolygons(
    fillColor = ~pal(landAreaKm),  # Fill based on landAreaKm
    color = "black",               # Border color
    weight = 1,                    # Border weight
    fillOpacity = 0.7,             # Fill opacity
    label = ~paste0("Country: ", name, 
                    "<br>Land Area: ", round(landAreaKm, 2), " km²"), # Tooltip label
    labelOptions = labelOptions(
      style = list("font-weight" = "normal", padding = "3px 8px"),
      textsize = "15px",
      direction = "auto"
    )
  ) %>%
  addLegend("bottomright", 
            pal = pal, 
            values = ~landAreaKm,
            title = "Land Area (km²)",
            labFormat = labelFormat(prefix = "")) %>%
  setView(lng = 0, lat = 20, zoom = 2)  # Center the map on the globe

Distribution of Net Change in Population

ggplot(data = world) +
  geom_sf(aes(fill = netChange), color = "black", size = 0.2) +  # Borders and fill by netChange
  scale_fill_gradient2(low = "blue", mid = "white", high = "red", 
                       midpoint = 0, name = "Net Change") +  # coolwarm color scale
  labs(title = "Distribution of Net Change in Population") +
  theme_minimal() +
  theme(
    plot.title = element_text(size = 16, face = "bold"),
    legend.position = "bottom"
  )

Distribution of Growth Rate of Population

ggplot(data = world) +
  geom_sf(aes(fill = growthRate), color = "black", size = 0.2) +  # Borders and fill by growthRate
  scale_fill_viridis_c(name = "Growth Rate", option = "viridis") +  # viridis color scale
  labs(title = "Distribution of Growth Rate of Population") +
  theme_minimal() +
  theme(
    plot.title = element_text(size = 16, face = "bold"),
    legend.position = "bottom"
  )

Distribution of World Percentage of Population by Location

ggplot(data = world) +
  geom_sf(aes(fill = worldPercentage), color = "black", size = 0.2) +  # Country borders and fill by worldPercentage
  scale_fill_gradient(low = "lightblue", high = "darkblue", name = "World Percentage") +  # Blues color scale
  labs(title = "Distribution of World Percentage of Population by Location") +
  theme_minimal() +
  theme(
    plot.title = element_text(size = 16, face = "bold"),
    legend.position = "bottom"
  )

Distribution of Population by Density

# Plotting using ggplot2
ggplot(data = world) +
  geom_sf(aes(fill = density), color = "black", size = 0.2) +  # Borders and fill by density
  scale_fill_gradient(low = "lightgreen", high = "darkgreen", name = "Density") +  # Greens color scale
  labs(title = "Distribution of Population by Density") +
  theme_minimal() +
  theme(
    plot.title = element_text(size = 16, face = "bold"),
    legend.position = "bottom"
  )

Distribution of Population by Density (per square mile)

ggplot(data = world) +
  geom_sf(aes(fill = densityMi), color = "black", size = 0.2) +  # Borders and fill by densityMi
  scale_fill_gradient(low = "lightyellow", high = "orange", name = "Density per sq mi") +  # Oranges color scale
  labs(title = "Distribution of Population by Density (per square mile)") +
  theme_minimal() +
  theme(
    plot.title = element_text(size = 16, face = "bold"),
    legend.position = "bottom"
  )

Conclusion

The analysis of global population trends from 1980 to 2050 highlights notable changes in population density and distribution worldwide. Interactive visualizations reveal regions experiencing significant population growth, particularly in developing nations, providing valuable insights into demographic patterns over time. The data also emphasizes the value of international data consistency, making it easier to analyze global demographic patterns and anticipate future demands across different regions and time frames.