Nations Charts Assignment

Author

Marie-Anne Kemajou

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.0.4     
── 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
nations <- read_csv("/Users/marieannekemajou/Documents/Data 110/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.
 head(nations)
# A tibble: 6 × 10
  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
# ℹ 2 more variables: region <chr>, income <chr>
nationdos <- nations %>%
  filter(!is.na(gdp_percap))
nation2 <- nationdos %>%
  mutate(gdp_trillion = (gdp_percap * population) / 1e12)
unique(nation2$country)
  [1] "United Arab Emirates"           "Afghanistan"                   
  [3] "Antigua and Barbuda"            "Albania"                       
  [5] "Armenia"                        "Angola"                        
  [7] "Austria"                        "Australia"                     
  [9] "Aruba"                          "Azerbaijan"                    
 [11] "Bosnia and Herzegovina"         "Barbados"                      
 [13] "Bangladesh"                     "Belgium"                       
 [15] "Burkina Faso"                   "Bulgaria"                      
 [17] "Bahrain"                        "Burundi"                       
 [19] "Benin"                          "Bermuda"                       
 [21] "Brunei Darussalam"              "Bolivia"                       
 [23] "Brazil"                         "Bahamas, The"                  
 [25] "Bhutan"                         "Botswana"                      
 [27] "Belarus"                        "Belize"                        
 [29] "Canada"                         "Congo, Dem. Rep."              
 [31] "Central African Republic"       "Congo, Rep."                   
 [33] "Switzerland"                    "Cote d'Ivoire"                 
 [35] "Chile"                          "Cameroon"                      
 [37] "China"                          "Colombia"                      
 [39] "Costa Rica"                     "Cuba"                          
 [41] "Cyprus"                         "Czech Republic"                
 [43] "Germany"                        "Djibouti"                      
 [45] "Denmark"                        "Dominica"                      
 [47] "Dominican Republic"             "Algeria"                       
 [49] "Ecuador"                        "Estonia"                       
 [51] "Egypt, Arab Rep."               "Eritrea"                       
 [53] "Spain"                          "Ethiopia"                      
 [55] "Finland"                        "Fiji"                          
 [57] "Micronesia, Fed. Sts."          "France"                        
 [59] "Gabon"                          "United Kingdom"                
 [61] "Grenada"                        "Georgia"                       
 [63] "Ghana"                          "Gambia, The"                   
 [65] "Guinea"                         "Equatorial Guinea"             
 [67] "Greece"                         "Guatemala"                     
 [69] "Guinea-Bissau"                  "Guyana"                        
 [71] "Hong Kong SAR, China"           "Honduras"                      
 [73] "Croatia"                        "Haiti"                         
 [75] "Hungary"                        "Indonesia"                     
 [77] "Ireland"                        "Israel"                        
 [79] "India"                          "Iraq"                          
 [81] "Iran, Islamic Rep."             "Iceland"                       
 [83] "Italy"                          "Jamaica"                       
 [85] "Jordan"                         "Japan"                         
 [87] "Kenya"                          "Kyrgyz Republic"               
 [89] "Cambodia"                       "Kiribati"                      
 [91] "Comoros"                        "St. Kitts and Nevis"           
 [93] "Korea, Rep."                    "Kuwait"                        
 [95] "Cayman Islands"                 "Kazakhstan"                    
 [97] "Lao PDR"                        "Lebanon"                       
 [99] "St. Lucia"                      "Sri Lanka"                     
[101] "Liberia"                        "Lesotho"                       
[103] "Lithuania"                      "Luxembourg"                    
[105] "Latvia"                         "Libya"                         
[107] "Morocco"                        "Moldova"                       
[109] "Montenegro"                     "Madagascar"                    
[111] "Marshall Islands"               "Macedonia, FYR"                
[113] "Mali"                           "Mongolia"                      
[115] "Macao SAR, China"               "Mauritania"                    
[117] "Malta"                          "Mauritius"                     
[119] "Maldives"                       "Malawi"                        
[121] "Mexico"                         "Malaysia"                      
[123] "Mozambique"                     "Namibia"                       
[125] "Niger"                          "Nigeria"                       
[127] "Nicaragua"                      "Netherlands"                   
[129] "Norway"                         "Nepal"                         
[131] "New Zealand"                    "Oman"                          
[133] "Panama"                         "Peru"                          
[135] "Papua New Guinea"               "Philippines"                   
[137] "Pakistan"                       "Poland"                        
[139] "Puerto Rico"                    "West Bank and Gaza"            
[141] "Portugal"                       "Palau"                         
[143] "Paraguay"                       "Qatar"                         
[145] "Romania"                        "Serbia"                        
[147] "Russian Federation"             "Rwanda"                        
[149] "Saudi Arabia"                   "Solomon Islands"               
[151] "Seychelles"                     "Sudan"                         
[153] "Sweden"                         "Singapore"                     
[155] "Slovenia"                       "Slovak Republic"               
[157] "Sierra Leone"                   "Senegal"                       
[159] "Suriname"                       "South Sudan"                   
[161] "Sao Tome and Principe"          "El Salvador"                   
[163] "Sint Maarten (Dutch part)"      "Swaziland"                     
[165] "Chad"                           "Togo"                          
[167] "Thailand"                       "Tajikistan"                    
[169] "Timor-Leste"                    "Turkmenistan"                  
[171] "Tunisia"                        "Tonga"                         
[173] "Turkey"                         "Trinidad and Tobago"           
[175] "Tuvalu"                         "Tanzania"                      
[177] "Ukraine"                        "Uganda"                        
[179] "United States"                  "Uruguay"                       
[181] "Uzbekistan"                     "St. Vincent and the Grenadines"
[183] "Venezuela, RB"                  "Vietnam"                       
[185] "Vanuatu"                        "Samoa"                         
[187] "Yemen, Rep."                    "South Africa"                  
[189] "Zambia"                         "Zimbabwe"                      
countries1 <- c("Sudan", "Nigeria", "Rwanda", "Nicaragua")
nation3 <- nation2 %>%
  filter(country %in% countries1)
ggplot(nation3, aes(x = year, y = gdp_trillion, color = country)) +
  geom_point() +  
  geom_line() +   
  scale_color_brewer(palette = "Set1") +
  labs(title = "Nigeria's Rapidly Inclining Economy",
       x = "Year",
       y = "GDP ($ trillion)",
       color = "Country") +
  theme_minimal()

nationsreg <- nation2 %>%
  group_by(region, year) %>%
  summarise(sum_GDP = sum(gdp_trillion, na.rm = TRUE)) 
`summarise()` has grouped output by 'region'. You can override using the
`.groups` argument.
ggplot(nationsreg, aes(x = year, y = sum_GDP, fill = region)) +
  geom_area(color = "white", linewidth = 0.3) + 
  scale_fill_brewer(palette = "Set2") +  
  labs(title = "GDP by World Bank Region",
       x = "Year",
       y = "GDP ($ trillion)",
       fill = "Region") +
  theme_minimal()