Test2

Author

Zachary Rodavich

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.2.0     ✔ readr     2.1.6
✔ forcats   1.0.1     ✔ stringr   1.6.0
✔ ggplot2   4.0.2     ✔ tibble    3.3.1
✔ lubridate 1.9.4     ✔ tidyr     1.3.2
✔ purrr     1.2.1     
── 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(ggfortify)
library(dplyr)
library(ggplot2)
getwd()
[1] "/Users/zacharyrodavich/Desktop"
setwd(dir = "/Users/zacharyrodavich/desktop")
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.
summary (nations)
    iso2c              iso3c             country               year     
 Length:5275        Length:5275        Length:5275        Min.   :1990  
 Class :character   Class :character   Class :character   1st Qu.:1996  
 Mode  :character   Mode  :character   Mode  :character   Median :2002  
                                                          Mean   :2002  
                                                          3rd Qu.:2008  
                                                          Max.   :2014  
                                                                        
   gdp_percap         population          birth_rate    neonat_mortal_rate
 Min.   :   239.7   Min.   :9.004e+03   Min.   : 6.90   Min.   : 0.70     
 1st Qu.:  2263.6   1st Qu.:7.175e+05   1st Qu.:13.40   1st Qu.: 6.70     
 Median :  6563.2   Median :5.303e+06   Median :21.60   Median :15.00     
 Mean   : 12788.8   Mean   :2.958e+07   Mean   :24.16   Mean   :19.40     
 3rd Qu.: 17195.0   3rd Qu.:1.757e+07   3rd Qu.:33.88   3rd Qu.:29.48     
 Max.   :141968.1   Max.   :1.364e+09   Max.   :55.12   Max.   :73.10     
 NA's   :766        NA's   :14          NA's   :295     NA's   :525       
    region             income         
 Length:5275        Length:5275       
 Class :character   Class :character  
 Mode  :character   Mode  :character  
                                      
                                      
                                      
                                      
 nations <- nations |>
  mutate(GDP = gdp_percap * population / 1000000000000)
p1 <- ggplot(nations, aes(x = GDP, y = year)) +
  labs(title = "GDP of Several Nations",
       caption = "Data Source",
       x = "GDP in Trillions of Dollars",
       y = "Year") +
       theme_minimal(base_size = 12)
p1 + geom_point()
Warning: Removed 766 rows containing missing values or values outside the scale range
(`geom_point()`).

nations2 <- nations |>
  filter (country == "Afghanistan") |>
    filter (!is.na(gdp_percap))

  head (nations2)
# 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 AF    AFG   Afghani…  2009      1526.   27207291       40.3               39.1
2 AF    AFG   Afghani…  2011      1713.   28809167       37.6               38.1
3 AF    AFG   Afghani…  2002       896.   21487079       47.2               43.9
4 AF    AFG   Afghani…  2012      1934.   29726803       36.4               37.4
5 AF    AFG   Afghani…  2005      1039.   24399948       44.9               41.7
6 AF    AFG   Afghani…  2010      1629.   27962207       38.9               38.7
# ℹ 3 more variables: region <chr>, income <chr>, GDP <dbl>
p2 <- ggplot(nations2, aes(x=GDP, y=year)) +
  labs(title = "GDP of Afghanastan",
       caption = "Data Source",
       x = "GDP in Trillions of Dollars",
       y = "Year") 
p2 + geom_point()

p3 <- p2 + geom_point() 
p3

p4 <- p3 + geom_smooth(color = "red")
p4
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'

The dot-plot and correlation above shows the GDP of Afghanistan between the Years 2000 and 2012. One thing that is noted was that at the time, the economy of Afghanistan was on the rise, despite the conflicts raging between the Taliban and the U.S. Government as a result of the “War on Terror” and the many refugees this conflict triggered. This was primarily a result of the U.S. installing a new government after successfully removing the Taliban from power.

NOTE: I acknowledge the use of ChatGPT (https://chatgpt.com/) to help the coding process by seeking explanations for errors found within my code, including if something wasn’t defined correctly, or if there was a syntax error present in my code. On March 14th, 2026, I uploaded a Screenshot of my code to ChatGPT with instructions to explain any errors I found in my code, so that I could understand what I needed to fix in order to have fully functioning code chunks. All code written is produced by me (Zachary Rodavich) and me only, and I have fully read and understood the Acceptable A.I. usage policies for this course.