Load libraries and dataset

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.2.1     ✔ readr     2.2.0
## ✔ forcats   1.0.1     ✔ stringr   1.6.0
## ✔ ggplot2   4.0.3     ✔ tibble    3.3.1
## ✔ lubridate 1.9.5     ✔ tidyr     1.3.2
## ✔ purrr     1.2.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(RColorBrewer)

# Load the dataset (adjust filename/path if necessary)
setwd("C:/Users/ryanj/Downloads")
nations <- read_csv("nations.csv")
## Rows: 5275 Columns: 10
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (5): iso2c, iso3c, country, region, income
## dbl (5): year, gdp_percap, population, birth_rate, neonat_mortal_rate
## 
## ℹ 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.
# Create the new GDP variable in trillions of dollars ($)
nations <- nations |>
  mutate(gdp_tn = (gdp_percap * population) / 1e12)
head(nations)
## # A tibble: 6 × 11
##   iso2c iso3c country  year gdp_percap population birth_rate neonat_mortal_rate
##   <chr> <chr> <chr>   <dbl>      <dbl>      <dbl>      <dbl>              <dbl>
## 1 AD    AND   Andorra  1996         NA      64291       10.9                2.8
## 2 AD    AND   Andorra  1994         NA      62707       10.9                3.2
## 3 AD    AND   Andorra  2003         NA      74783       10.3                2  
## 4 AD    AND   Andorra  1990         NA      54511       11.9                4.3
## 5 AD    AND   Andorra  2009         NA      85474        9.9                1.7
## 6 AD    AND   Andorra  2011         NA      82326       NA                  1.6
## # ℹ 3 more variables: region <chr>, income <chr>, gdp_tn <dbl>
unique(nations$country)
##   [1] "Andorra"                        "United Arab Emirates"          
##   [3] "Afghanistan"                    "Antigua and Barbuda"           
##   [5] "Albania"                        "Armenia"                       
##   [7] "Angola"                         "Argentina"                     
##   [9] "American Samoa"                 "Austria"                       
##  [11] "Australia"                      "Aruba"                         
##  [13] "Azerbaijan"                     "Bosnia and Herzegovina"        
##  [15] "Barbados"                       "Bangladesh"                    
##  [17] "Belgium"                        "Burkina Faso"                  
##  [19] "Bulgaria"                       "Bahrain"                       
##  [21] "Burundi"                        "Benin"                         
##  [23] "Bermuda"                        "Brunei Darussalam"             
##  [25] "Bolivia"                        "Brazil"                        
##  [27] "Bahamas, The"                   "Bhutan"                        
##  [29] "Botswana"                       "Belarus"                       
##  [31] "Belize"                         "Canada"                        
##  [33] "Congo, Dem. Rep."               "Central African Republic"      
##  [35] "Congo, Rep."                    "Switzerland"                   
##  [37] "Cote d'Ivoire"                  "Chile"                         
##  [39] "Cameroon"                       "China"                         
##  [41] "Colombia"                       "Costa Rica"                    
##  [43] "Cuba"                           "Curacao"                       
##  [45] "Cyprus"                         "Czech Republic"                
##  [47] "Germany"                        "Djibouti"                      
##  [49] "Denmark"                        "Dominica"                      
##  [51] "Dominican Republic"             "Algeria"                       
##  [53] "Ecuador"                        "Estonia"                       
##  [55] "Egypt, Arab Rep."               "Eritrea"                       
##  [57] "Spain"                          "Ethiopia"                      
##  [59] "Finland"                        "Fiji"                          
##  [61] "Micronesia, Fed. Sts."          "France"                        
##  [63] "Gabon"                          "United Kingdom"                
##  [65] "Grenada"                        "Georgia"                       
##  [67] "Ghana"                          "Gibraltar"                     
##  [69] "Greenland"                      "Gambia, The"                   
##  [71] "Guinea"                         "Equatorial Guinea"             
##  [73] "Greece"                         "Guatemala"                     
##  [75] "Guam"                           "Guinea-Bissau"                 
##  [77] "Guyana"                         "Hong Kong SAR, China"          
##  [79] "Honduras"                       "Croatia"                       
##  [81] "Haiti"                          "Hungary"                       
##  [83] "Indonesia"                      "Ireland"                       
##  [85] "Israel"                         "Isle of Man"                   
##  [87] "India"                          "Iraq"                          
##  [89] "Iran, Islamic Rep."             "Iceland"                       
##  [91] "Italy"                          "Channel Islands"               
##  [93] "Jamaica"                        "Jordan"                        
##  [95] "Japan"                          "Kenya"                         
##  [97] "Kyrgyz Republic"                "Cambodia"                      
##  [99] "Kiribati"                       "Comoros"                       
## [101] "St. Kitts and Nevis"            "Korea, Rep."                   
## [103] "Kuwait"                         "Cayman Islands"                
## [105] "Kazakhstan"                     "Lao PDR"                       
## [107] "Lebanon"                        "St. Lucia"                     
## [109] "Liechtenstein"                  "Sri Lanka"                     
## [111] "Liberia"                        "Lesotho"                       
## [113] "Lithuania"                      "Luxembourg"                    
## [115] "Latvia"                         "Libya"                         
## [117] "Morocco"                        "Monaco"                        
## [119] "Moldova"                        "Montenegro"                    
## [121] "St. Martin (French part)"       "Madagascar"                    
## [123] "Marshall Islands"               "Macedonia, FYR"                
## [125] "Mali"                           "Myanmar"                       
## [127] "Mongolia"                       "Macao SAR, China"              
## [129] "Northern Mariana Islands"       "Mauritania"                    
## [131] "Malta"                          "Mauritius"                     
## [133] "Maldives"                       "Malawi"                        
## [135] "Mexico"                         "Malaysia"                      
## [137] "Mozambique"                     "Namibia"                       
## [139] "New Caledonia"                  "Niger"                         
## [141] "Nigeria"                        "Nicaragua"                     
## [143] "Netherlands"                    "Norway"                        
## [145] "Nepal"                          "New Zealand"                   
## [147] "Oman"                           "Panama"                        
## [149] "Peru"                           "French Polynesia"              
## [151] "Papua New Guinea"               "Philippines"                   
## [153] "Pakistan"                       "Poland"                        
## [155] "Puerto Rico"                    "West Bank and Gaza"            
## [157] "Portugal"                       "Palau"                         
## [159] "Paraguay"                       "Qatar"                         
## [161] "Romania"                        "Serbia"                        
## [163] "Russian Federation"             "Rwanda"                        
## [165] "Saudi Arabia"                   "Solomon Islands"               
## [167] "Seychelles"                     "Sudan"                         
## [169] "Sweden"                         "Singapore"                     
## [171] "Slovenia"                       "Slovak Republic"               
## [173] "Sierra Leone"                   "San Marino"                    
## [175] "Senegal"                        "Somalia"                       
## [177] "Suriname"                       "South Sudan"                   
## [179] "Sao Tome and Principe"          "El Salvador"                   
## [181] "Sint Maarten (Dutch part)"      "Syrian Arab Republic"          
## [183] "Swaziland"                      "Turks and Caicos Islands"      
## [185] "Chad"                           "Togo"                          
## [187] "Thailand"                       "Tajikistan"                    
## [189] "Timor-Leste"                    "Turkmenistan"                  
## [191] "Tunisia"                        "Tonga"                         
## [193] "Turkey"                         "Trinidad and Tobago"           
## [195] "Tuvalu"                         "Tanzania"                      
## [197] "Ukraine"                        "Uganda"                        
## [199] "United States"                  "Uruguay"                       
## [201] "Uzbekistan"                     "St. Vincent and the Grenadines"
## [203] "Venezuela, RB"                  "Virgin Islands (U.S.)"         
## [205] "Vietnam"                        "Vanuatu"                       
## [207] "Samoa"                          "Yemen, Rep."                   
## [209] "South Africa"                   "Zambia"                        
## [211] "Zimbabwe"
unique(nations$iso3c)
##   [1] "AND" "ARE" "AFG" "ATG" "ALB" "ARM" "AGO" "ARG" "ASM" "AUT" "AUS" "ABW"
##  [13] "AZE" "BIH" "BRB" "BGD" "BEL" "BFA" "BGR" "BHR" "BDI" "BEN" "BMU" "BRN"
##  [25] "BOL" "BRA" "BHS" "BTN" "BWA" "BLR" "BLZ" "CAN" "COD" "CAF" "COG" "CHE"
##  [37] "CIV" "CHL" "CMR" "CHN" "COL" "CRI" "CUB" "CUW" "CYP" "CZE" "DEU" "DJI"
##  [49] "DNK" "DMA" "DOM" "DZA" "ECU" "EST" "EGY" "ERI" "ESP" "ETH" "FIN" "FJI"
##  [61] "FSM" "FRA" "GAB" "GBR" "GRD" "GEO" "GHA" "GIB" "GRL" "GMB" "GIN" "GNQ"
##  [73] "GRC" "GTM" "GUM" "GNB" "GUY" "HKG" "HND" "HRV" "HTI" "HUN" "IDN" "IRL"
##  [85] "ISR" "IMN" "IND" "IRQ" "IRN" "ISL" "ITA" "CHI" "JAM" "JOR" "JPN" "KEN"
##  [97] "KGZ" "KHM" "KIR" "COM" "KNA" "KOR" "KWT" "CYM" "KAZ" "LAO" "LBN" "LCA"
## [109] "LIE" "LKA" "LBR" "LSO" "LTU" "LUX" "LVA" "LBY" "MAR" "MCO" "MDA" "MNE"
## [121] "MAF" "MDG" "MHL" "MKD" "MLI" "MMR" "MNG" "MAC" "MNP" "MRT" "MLT" "MUS"
## [133] "MDV" "MWI" "MEX" "MYS" "MOZ" "NAM" "NCL" "NER" "NGA" "NIC" "NLD" "NOR"
## [145] "NPL" "NZL" "OMN" "PAN" "PER" "PYF" "PNG" "PHL" "PAK" "POL" "PRI" "PSE"
## [157] "PRT" "PLW" "PRY" "QAT" "ROU" "SRB" "RUS" "RWA" "SAU" "SLB" "SYC" "SDN"
## [169] "SWE" "SGP" "SVN" "SVK" "SLE" "SMR" "SEN" "SOM" "SUR" "SSD" "STP" "SLV"
## [181] "SXM" "SYR" "SWZ" "TCA" "TCD" "TGO" "THA" "TJK" "TLS" "TKM" "TUN" "TON"
## [193] "TUR" "TTO" "TUV" "TZA" "UKR" "UGA" "USA" "URY" "UZB" "VCT" "VEN" "VIR"
## [205] "VNM" "VUT" "WSM" "YEM" "ZAF" "ZMB" "ZWE"

Chart 1

# Filter for four specific countries
big4 <- nations |>
  filter(iso3c %in% c("PER", "PHL", "COL", "HND"))

# Draw static Chart 1
ggplot(big4, aes(x = year, y = gdp_tn, color = country)) +
  geom_line(linewidth = 1) +
  geom_point(size = 2) +
  scale_color_brewer(palette = "Set1") +
  labs(
    title = "GDP ($ trillion) for Desired  Countries",
    x = "Year",
    y = "GDP ($ trillion)",
    color = "Country"
  ) +
  theme_minimal(base_size = 14)

Chart 2

# Group and summarize data by region and year
regions <- nations |>
  group_by(region, year) |>
  summarise(GDP = sum(gdp_tn, na.rm = TRUE), .groups = "drop")

# Drawing static Chart 2
ggplot(regions, aes(x = year, y = GDP, fill = region)) +
  geom_area(color = "white", linewidth = 0.5) + # Thin white line around areas
  scale_fill_brewer(palette = "Set2") +
  labs(
    title = "Total GDP by Region Over Time",
    x = "Year",
    y = "GDP ($ trillion)",
    fill = "Region"
  ) +
  theme_minimal(base_size = 14)