### PS4

options(repos = c(CRAN = "https://cran.rstudio.com"))


install.packages("tidyverse")
## 
## The downloaded binary packages are in
##  /var/folders/rz/h261r9g93pz6tzgqk1tt08_h0000gn/T//RtmpHysJKe/downloaded_packages
install.packages("dplyr")
## 
## The downloaded binary packages are in
##  /var/folders/rz/h261r9g93pz6tzgqk1tt08_h0000gn/T//RtmpHysJKe/downloaded_packages
install.packages("tibble")
## 
## The downloaded binary packages are in
##  /var/folders/rz/h261r9g93pz6tzgqk1tt08_h0000gn/T//RtmpHysJKe/downloaded_packages
##uploaded data through import dataset
library(readxl)
capacity_lac <- read_excel("~/Downloads/capacity-lac.xlsx", 
                           col_types = c("text", "numeric", "numeric", 
                                         "numeric", "numeric", "numeric", 
                                         "numeric", "numeric", "numeric", "numeric", 
                                         "numeric", "numeric", "numeric", "numeric", "numeric", 
                                         "numeric", "numeric", "numeric", "numeric", "numeric", 
                                         "numeric", "numeric", "numeric", "numeric", "numeric", 
                                         "numeric", "numeric", "numeric", "numeric", "numeric", 
                                         "numeric", "numeric", "numeric", 
                                         "numeric", "numeric", "numeric", 
                                         "numeric", "numeric", "numeric", 
                                         "numeric", "numeric", "numeric", 
                                         "numeric", "numeric", "numeric", 
                                         "numeric", "numeric", "numeric", 
                                         "numeric", "numeric", "numeric", 
                                         "numeric", "numeric", "numeric", 
                                         "numeric", "numeric", "numeric", 
                                         "numeric", "numeric", "numeric", 
                                         "numeric", "numeric", "numeric", 
                                         "numeric", "numeric", "numeric", 
                                         "numeric", "numeric", "numeric", 
                                         "numeric", "numeric", "numeric", 
                                         "numeric", "numeric", "numeric", 
                                         "numeric", "numeric", "numeric", 
                                         "numeric", "numeric", "numeric", 
                                         "numeric", "numeric", "numeric", 
                                         "numeric", "numeric", "numeric", 
                                         "numeric", "numeric", "numeric", 
                                         "numeric", "numeric", "numeric", 
                                         "numeric", "numeric", "numeric", 
                                         "numeric", "numeric", "numeric",
                                         "numeric", "numeric", "numeric",
                                         "numeric", "numeric", "numeric",
                                         "numeric", "numeric", "numeric",
                                         "numeric", "numeric", "numeric",
                                         "numeric", "numeric", "numeric",
                                         "numeric", "numeric", "numeric",
                                         "numeric", "numeric", "numeric",
                                         "numeric", "numeric", "numeric", 
                                         "numeric"),skip = 1)
## Warning: Expecting numeric in Q8 / R8C17: got 'NA'
## Warning: Expecting numeric in R8 / R8C18: got 'NA'
## Warning: Expecting numeric in S8 / R8C19: got 'NA'
## Warning: Expecting numeric in T8 / R8C20: got 'NA'
## Warning: Expecting numeric in U8 / R8C21: got 'NA'
## Warning: Expecting numeric in V8 / R8C22: got 'NA'
## Warning: Expecting numeric in W8 / R8C23: got 'NA'
## Warning: Expecting numeric in X8 / R8C24: got 'NA'
## Warning: Expecting numeric in Y8 / R8C25: got 'NA'
## Warning: Expecting numeric in Z8 / R8C26: got 'NA'
## Warning: Expecting numeric in AA8 / R8C27: got 'NA'
## Warning: Expecting numeric in AB8 / R8C28: got 'NA'
## Warning: Expecting numeric in AC8 / R8C29: got 'NA'
## Warning: Expecting numeric in AD8 / R8C30: got 'NA'
## Warning: Expecting numeric in AE8 / R8C31: got 'NA'
## Warning: Expecting numeric in AF8 / R8C32: got 'NA'
## Warning: Expecting numeric in AG8 / R8C33: got 'NA'
## Warning: Expecting numeric in AH8 / R8C34: got 'NA'
## Warning: Expecting numeric in AI8 / R8C35: got 'NA'
## Warning: Expecting numeric in B18 / R18C2: got 'NA'
## Warning: Expecting numeric in C18 / R18C3: got 'NA'
## Warning: Expecting numeric in D18 / R18C4: got 'NA'
## Warning: Expecting numeric in B21 / R21C2: got 'NA'
## Warning: Expecting numeric in C21 / R21C3: got 'NA'
View(capacity_lac)


#1 creating a variable 

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
TC_change <- capacity_lac %>%
  mutate(change =(((`2022`-`1945`)/`1945`))*100) %>%
  select(change, everything())

View(TC_change)
print(TC_change$change)
##  [1]  -7.11770833  12.66005387   3.88349515  -2.18520274  21.45454545
##  [6]  -3.40909091  23.52941176 -10.30478069   7.33695652  -3.29670330
## [11]  15.75189873  -3.84615385  -0.02530124  -3.34190231   5.76923077
## [16]  27.19342105   0.76785102  -5.21919192  -0.50761421   0.50251256
## answer is 



#2 creating time series plot 

##Plot time series data

summary(capacity_lac)
##    country               1900            1901            1902      
##  Length:20          Min.   :59.17   Min.   :59.17   Min.   :59.17  
##  Class :character   1st Qu.:74.18   1st Qu.:74.46   1st Qu.:74.42  
##  Mode  :character   Median :86.50   Median :85.79   Median :86.57  
##                     Mean   :82.98   Mean   :83.36   Mean   :84.21  
##                     3rd Qu.:94.54   3rd Qu.:94.54   3rd Qu.:95.66  
##                     Max.   :98.33   Max.   :99.17   Max.   :99.17  
##                     NA's   :2       NA's   :2       NA's   :1      
##       1903            1904            1905            1906      
##  Min.   :58.67   Min.   :61.43   Min.   :68.00   Min.   :68.00  
##  1st Qu.:72.50   1st Qu.:75.96   1st Qu.:78.73   1st Qu.:78.73  
##  Median :85.79   Median :86.57   Median :88.50   Median :86.57  
##  Mean   :83.25   Mean   :85.00   Mean   :86.68   Mean   :86.63  
##  3rd Qu.:95.40   3rd Qu.:95.40   3rd Qu.:95.40   3rd Qu.:95.40  
##  Max.   :99.17   Max.   :99.17   Max.   :99.17   Max.   :99.24  
##                                                                 
##       1907            1908            1909            1910      
##  Min.   :68.00   Min.   :68.00   Min.   :68.00   Min.   :68.00  
##  1st Qu.:78.73   1st Qu.:78.73   1st Qu.:78.73   1st Qu.:78.62  
##  Median :86.57   Median :86.57   Median :89.74   Median :86.57  
##  Mean   :86.63   Mean   :86.64   Mean   :87.46   Mean   :86.80  
##  3rd Qu.:95.40   3rd Qu.:95.40   3rd Qu.:96.50   3rd Qu.:95.73  
##  Max.   :99.24   Max.   :99.24   Max.   :99.24   Max.   :99.24  
##                                                                 
##       1911            1912            1913            1914      
##  Min.   :68.00   Min.   :59.67   Min.   :59.67   Min.   :59.67  
##  1st Qu.:77.75   1st Qu.:77.12   1st Qu.:77.12   1st Qu.:75.75  
##  Median :86.57   Median :86.57   Median :86.57   Median :86.57  
##  Mean   :86.30   Mean   :85.24   Mean   :85.27   Mean   :84.72  
##  3rd Qu.:95.73   3rd Qu.:95.73   3rd Qu.:95.73   3rd Qu.:95.73  
##  Max.   :99.24   Max.   :99.24   Max.   :99.24   Max.   :99.24  
##                                                                 
##       1915            1916            1917            1918      
##  Min.   :59.67   Min.   :41.17   Min.   :41.17   Min.   :41.17  
##  1st Qu.:75.50   1st Qu.:75.58   1st Qu.:75.58   1st Qu.:75.58  
##  Median :88.14   Median :88.14   Median :88.14   Median :88.14  
##  Mean   :84.98   Mean   :84.27   Mean   :83.94   Mean   :83.94  
##  3rd Qu.:96.32   3rd Qu.:96.32   3rd Qu.:95.46   3rd Qu.:95.46  
##  Max.   :99.24   Max.   :99.24   Max.   :99.24   Max.   :99.24  
##  NA's   :1       NA's   :1       NA's   :1       NA's   :1      
##       1919            1920            1921            1922      
##  Min.   :41.17   Min.   :41.17   Min.   :41.17   Min.   :41.17  
##  1st Qu.:75.58   1st Qu.:75.58   1st Qu.:77.17   1st Qu.:77.17  
##  Median :88.14   Median :89.43   Median :89.43   Median :89.43  
##  Mean   :83.94   Mean   :84.35   Mean   :84.54   Mean   :84.54  
##  3rd Qu.:95.46   3rd Qu.:96.18   3rd Qu.:96.18   3rd Qu.:96.18  
##  Max.   :99.24   Max.   :99.24   Max.   :99.24   Max.   :99.24  
##  NA's   :1       NA's   :1       NA's   :1       NA's   :1      
##       1923            1924            1925            1926      
##  Min.   :41.17   Min.   :55.40   Min.   :68.00   Min.   :68.00  
##  1st Qu.:77.17   1st Qu.:77.17   1st Qu.:78.92   1st Qu.:78.92  
##  Median :89.43   Median :89.43   Median :91.89   Median :91.89  
##  Mean   :84.54   Mean   :85.29   Mean   :87.74   Mean   :87.90  
##  3rd Qu.:96.18   3rd Qu.:96.18   3rd Qu.:96.25   3rd Qu.:96.25  
##  Max.   :99.24   Max.   :99.24   Max.   :99.24   Max.   :99.24  
##  NA's   :1       NA's   :1       NA's   :1       NA's   :1      
##       1927            1928            1929            1930      
##  Min.   :68.00   Min.   :68.00   Min.   :68.00   Min.   :68.00  
##  1st Qu.:78.92   1st Qu.:78.92   1st Qu.:78.92   1st Qu.:78.92  
##  Median :91.89   Median :91.89   Median :91.89   Median :91.17  
##  Mean   :87.90   Mean   :87.90   Mean   :87.95   Mean   :88.12  
##  3rd Qu.:96.25   3rd Qu.:96.25   3rd Qu.:96.75   3rd Qu.:97.92  
##  Max.   :99.24   Max.   :99.24   Max.   :99.24   Max.   :99.24  
##  NA's   :1       NA's   :1       NA's   :1       NA's   :1      
##       1931            1932            1933            1934      
##  Min.   :68.00   Min.   :67.25   Min.   :67.25   Min.   :64.75  
##  1st Qu.:77.17   1st Qu.:77.17   1st Qu.:77.17   1st Qu.:77.75  
##  Median :91.17   Median :92.00   Median :92.00   Median :91.06  
##  Mean   :88.04   Mean   :87.79   Mean   :87.87   Mean   :87.55  
##  3rd Qu.:97.92   3rd Qu.:97.92   3rd Qu.:97.92   3rd Qu.:97.71  
##  Max.   :99.24   Max.   :99.24   Max.   :99.24   Max.   :99.24  
##  NA's   :1       NA's   :1       NA's   :1                      
##       1935            1936            1937            1938      
##  Min.   :64.75   Min.   :67.25   Min.   :68.00   Min.   :68.00  
##  1st Qu.:78.83   1st Qu.:78.83   1st Qu.:78.83   1st Qu.:78.83  
##  Median :91.40   Median :91.06   Median :91.06   Median :91.06  
##  Mean   :88.06   Mean   :88.19   Mean   :88.27   Mean   :88.27  
##  3rd Qu.:97.71   3rd Qu.:97.71   3rd Qu.:97.71   3rd Qu.:97.71  
##  Max.   :99.24   Max.   :99.24   Max.   :99.24   Max.   :99.24  
##                                                                 
##       1939            1940            1941            1942      
##  Min.   :68.00   Min.   :68.00   Min.   :68.00   Min.   :68.00  
##  1st Qu.:78.83   1st Qu.:79.45   1st Qu.:79.45   1st Qu.:79.45  
##  Median :91.06   Median :91.50   Median :91.50   Median :91.50  
##  Mean   :88.27   Mean   :88.74   Mean   :88.68   Mean   :88.76  
##  3rd Qu.:97.71   3rd Qu.:97.71   3rd Qu.:97.71   3rd Qu.:97.71  
##  Max.   :99.24   Max.   :99.24   Max.   :99.24   Max.   :99.24  
##                                                                 
##       1943            1944            1945            1946      
##  Min.   :68.00   Min.   :68.00   Min.   :68.00   Min.   :68.75  
##  1st Qu.:79.45   1st Qu.:78.83   1st Qu.:79.45   1st Qu.:79.45  
##  Median :91.50   Median :91.50   Median :91.50   Median :91.50  
##  Mean   :88.85   Mean   :88.26   Mean   :88.56   Mean   :89.09  
##  3rd Qu.:97.71   3rd Qu.:97.71   3rd Qu.:97.71   3rd Qu.:97.71  
##  Max.   :99.24   Max.   :99.24   Max.   :99.24   Max.   :99.24  
##                                                                 
##       1947            1948            1949            1950      
##  Min.   :68.75   Min.   :68.75   Min.   :61.75   Min.   :69.50  
##  1st Qu.:79.45   1st Qu.:79.45   1st Qu.:79.45   1st Qu.:79.45  
##  Median :91.50   Median :90.56   Median :90.56   Median :92.60  
##  Mean   :89.09   Mean   :88.45   Mean   :88.09   Mean   :88.84  
##  3rd Qu.:97.71   3rd Qu.:97.71   3rd Qu.:97.71   3rd Qu.:97.62  
##  Max.   :99.24   Max.   :99.24   Max.   :99.24   Max.   :99.24  
##                                                                 
##       1951            1952            1953            1954      
##  Min.   :69.50   Min.   :69.80   Min.   :69.80   Min.   :70.80  
##  1st Qu.:79.45   1st Qu.:79.45   1st Qu.:79.58   1st Qu.:79.38  
##  Median :92.60   Median :92.60   Median :92.60   Median :92.60  
##  Mean   :88.84   Mean   :89.22   Mean   :89.34   Mean   :89.55  
##  3rd Qu.:97.62   3rd Qu.:97.62   3rd Qu.:97.62   3rd Qu.:97.62  
##  Max.   :99.24   Max.   :99.24   Max.   :99.24   Max.   :99.24  
##                                                                 
##       1955            1956            1957            1958      
##  Min.   :70.80   Min.   :70.80   Min.   :70.80   Min.   :74.80  
##  1st Qu.:83.33   1st Qu.:83.33   1st Qu.:85.35   1st Qu.:85.35  
##  Median :92.60   Median :92.60   Median :92.60   Median :92.60  
##  Mean   :89.96   Mean   :89.96   Mean   :90.37   Mean   :90.52  
##  3rd Qu.:97.62   3rd Qu.:97.62   3rd Qu.:97.62   3rd Qu.:97.62  
##  Max.   :99.24   Max.   :99.24   Max.   :99.24   Max.   :99.24  
##                                                                 
##       1959            1960            1961            1962      
##  Min.   :74.80   Min.   :74.20   Min.   :74.20   Min.   :74.20  
##  1st Qu.:85.35   1st Qu.:84.88   1st Qu.:84.88   1st Qu.:84.88  
##  Median :92.60   Median :92.60   Median :92.60   Median :92.60  
##  Mean   :90.55   Mean   :90.22   Mean   :90.12   Mean   :90.12  
##  3rd Qu.:97.71   3rd Qu.:98.42   3rd Qu.:97.71   3rd Qu.:97.71  
##  Max.   :99.24   Max.   :99.24   Max.   :99.24   Max.   :99.24  
##                                                                 
##       1963            1964            1965            1966      
##  Min.   :74.20   Min.   :70.00   Min.   :58.20   Min.   :72.20  
##  1st Qu.:84.88   1st Qu.:84.88   1st Qu.:78.78   1st Qu.:84.88  
##  Median :92.60   Median :92.60   Median :90.56   Median :92.60  
##  Mean   :90.25   Mean   :90.01   Mean   :88.08   Mean   :89.94  
##  3rd Qu.:98.42   3rd Qu.:98.42   3rd Qu.:97.71   3rd Qu.:97.71  
##  Max.   :99.75   Max.   :99.75   Max.   :99.75   Max.   :99.75  
##                                                                 
##       1967            1968            1969            1970      
##  Min.   :72.20   Min.   :72.20   Min.   :72.20   Min.   :72.20  
##  1st Qu.:84.69   1st Qu.:84.94   1st Qu.:84.94   1st Qu.:85.25  
##  Median :92.60   Median :92.60   Median :92.60   Median :92.80  
##  Mean   :89.91   Mean   :89.96   Mean   :89.96   Mean   :89.99  
##  3rd Qu.:97.71   3rd Qu.:97.71   3rd Qu.:97.71   3rd Qu.:97.71  
##  Max.   :99.75   Max.   :99.75   Max.   :99.75   Max.   :99.75  
##                                                                 
##       1971            1972            1973            1974      
##  Min.   :72.20   Min.   :72.20   Min.   :72.20   Min.   :72.20  
##  1st Qu.:85.25   1st Qu.:85.25   1st Qu.:85.25   1st Qu.:85.25  
##  Median :92.80   Median :92.80   Median :92.80   Median :92.80  
##  Mean   :90.03   Mean   :90.03   Mean   :90.03   Mean   :90.01  
##  3rd Qu.:97.71   3rd Qu.:97.71   3rd Qu.:97.71   3rd Qu.:97.71  
##  Max.   :99.75   Max.   :99.75   Max.   :99.75   Max.   :99.75  
##                                                                 
##       1975            1976            1977            1978      
##  Min.   :72.20   Min.   :72.20   Min.   :69.20   Min.   :69.20  
##  1st Qu.:85.25   1st Qu.:85.25   1st Qu.:85.25   1st Qu.:85.25  
##  Median :92.80   Median :92.80   Median :92.80   Median :92.80  
##  Mean   :90.01   Mean   :90.11   Mean   :89.88   Mean   :89.88  
##  3rd Qu.:97.71   3rd Qu.:97.78   3rd Qu.:98.08   3rd Qu.:98.08  
##  Max.   :99.75   Max.   :99.75   Max.   :99.75   Max.   :99.75  
##                                                                 
##       1979            1980            1981            1982      
##  Min.   :72.20   Min.   :70.00   Min.   :70.00   Min.   :68.20  
##  1st Qu.:85.25   1st Qu.:84.00   1st Qu.:84.00   1st Qu.:83.00  
##  Median :92.80   Median :90.48   Median :90.48   Median :90.48  
##  Mean   :90.09   Mean   :88.71   Mean   :88.62   Mean   :88.42  
##  3rd Qu.:98.08   3rd Qu.:96.37   3rd Qu.:96.37   3rd Qu.:96.37  
##  Max.   :99.75   Max.   :99.75   Max.   :99.75   Max.   :99.75  
##                                                                 
##       1983            1984            1985            1986      
##  Min.   :68.20   Min.   :68.20   Min.   :68.20   Min.   :68.20  
##  1st Qu.:84.25   1st Qu.:84.25   1st Qu.:85.25   1st Qu.:83.84  
##  Median :90.48   Median :90.48   Median :90.48   Median :88.69  
##  Mean   :88.65   Mean   :88.75   Mean   :89.00   Mean   :88.66  
##  3rd Qu.:96.37   3rd Qu.:96.37   3rd Qu.:96.37   3rd Qu.:97.37  
##  Max.   :99.75   Max.   :99.75   Max.   :99.75   Max.   :99.75  
##                                                                 
##       1987            1988            1989            1990      
##  Min.   :68.00   Min.   :66.20   Min.   :66.20   Min.   :66.20  
##  1st Qu.:83.35   1st Qu.:83.92   1st Qu.:83.92   1st Qu.:85.38  
##  Median :88.69   Median :88.69   Median :88.69   Median :90.06  
##  Mean   :88.52   Mean   :88.46   Mean   :88.56   Mean   :89.49  
##  3rd Qu.:97.37   3rd Qu.:97.37   3rd Qu.:97.37   3rd Qu.:97.37  
##  Max.   :99.75   Max.   :99.75   Max.   :99.75   Max.   :99.75  
##                                                                 
##       1991            1992            1993            1994      
##  Min.   :66.20   Min.   :66.20   Min.   :66.20   Min.   :64.20  
##  1st Qu.:84.08   1st Qu.:84.08   1st Qu.:84.08   1st Qu.:85.54  
##  Median :90.33   Median :90.33   Median :90.69   Median :90.69  
##  Mean   :89.39   Mean   :89.62   Mean   :90.03   Mean   :90.15  
##  3rd Qu.:97.37   3rd Qu.:97.37   3rd Qu.:97.37   3rd Qu.:97.37  
##  Max.   :99.75   Max.   :99.75   Max.   :99.75   Max.   :99.75  
##                                                                 
##       1995            1996            1997            1998      
##  Min.   :64.20   Min.   :64.20   Min.   :64.20   Min.   :62.00  
##  1st Qu.:86.85   1st Qu.:86.85   1st Qu.:86.85   1st Qu.:86.85  
##  Median :91.37   Median :91.37   Median :91.37   Median :91.37  
##  Mean   :90.52   Mean   :90.52   Mean   :90.59   Mean   :90.48  
##  3rd Qu.:97.37   3rd Qu.:97.37   3rd Qu.:97.37   3rd Qu.:97.37  
##  Max.   :99.75   Max.   :99.75   Max.   :99.75   Max.   :99.75  
##                                                                 
##       1999            2000            2001            2002      
##  Min.   :62.00   Min.   :64.00   Min.   :64.00   Min.   :71.00  
##  1st Qu.:86.57   1st Qu.:87.55   1st Qu.:87.55   1st Qu.:87.67  
##  Median :91.37   Median :90.90   Median :90.77   Median :90.77  
##  Mean   :90.21   Mean   :90.56   Mean   :90.43   Mean   :90.89  
##  3rd Qu.:96.18   3rd Qu.:96.03   3rd Qu.:96.03   3rd Qu.:96.03  
##  Max.   :99.24   Max.   :99.24   Max.   :99.24   Max.   :99.24  
##                                                                 
##       2003            2004            2005            2006      
##  Min.   :76.92   Min.   :76.92   Min.   :76.92   Min.   :77.69  
##  1st Qu.:87.21   1st Qu.:88.15   1st Qu.:89.55   1st Qu.:89.81  
##  Median :90.77   Median :90.77   Median :90.83   Median :90.83  
##  Mean   :91.04   Mean   :91.20   Mean   :91.84   Mean   :91.96  
##  3rd Qu.:96.03   3rd Qu.:96.03   3rd Qu.:96.03   3rd Qu.:96.03  
##  Max.   :99.24   Max.   :99.24   Max.   :99.24   Max.   :99.24  
##                                                                 
##       2007            2008            2009            2010      
##  Min.   :80.77   Min.   :80.77   Min.   :80.77   Min.   :81.46  
##  1st Qu.:89.51   1st Qu.:89.51   1st Qu.:89.25   1st Qu.:89.78  
##  Median :91.86   Median :91.86   Median :91.86   Median :91.71  
##  Mean   :92.19   Mean   :92.15   Mean   :91.97   Mean   :92.08  
##  3rd Qu.:96.03   3rd Qu.:96.03   3rd Qu.:96.03   3rd Qu.:96.86  
##  Max.   :99.24   Max.   :99.24   Max.   :99.24   Max.   :99.24  
##                                                                 
##       2011            2012            2013            2014      
##  Min.   :81.46   Min.   :81.46   Min.   :79.40   Min.   :80.15  
##  1st Qu.:89.78   1st Qu.:89.70   1st Qu.:89.88   1st Qu.:89.69  
##  Median :91.71   Median :91.70   Median :92.37   Median :92.37  
##  Mean   :92.07   Mean   :92.05   Mean   :91.82   Mean   :91.79  
##  3rd Qu.:96.67   3rd Qu.:96.67   3rd Qu.:96.63   3rd Qu.:96.63  
##  Max.   :99.24   Max.   :99.24   Max.   :99.24   Max.   :99.24  
##                                                                 
##       2015            2016            2017            2018      
##  Min.   :80.15   Min.   :80.17   Min.   :80.17   Min.   :80.17  
##  1st Qu.:87.80   1st Qu.:89.15   1st Qu.:88.84   1st Qu.:88.18  
##  Median :92.37   Median :92.37   Median :92.05   Median :92.67  
##  Mean   :91.75   Mean   :91.94   Mean   :91.74   Mean   :91.48  
##  3rd Qu.:96.57   3rd Qu.:96.21   3rd Qu.:96.00   3rd Qu.:95.50  
##  Max.   :99.24   Max.   :99.24   Max.   :99.24   Max.   :99.24  
##                                                                 
##       2019            2020            2021            2022       
##  Min.   :80.00   Min.   :80.17   Min.   :77.50   Min.   : 80.00  
##  1st Qu.:87.94   1st Qu.:87.30   1st Qu.:87.90   1st Qu.: 87.31  
##  Median :91.78   Median :91.93   Median :92.00   Median : 92.53  
##  Mean   :91.26   Mean   :91.20   Mean   :90.72   Mean   : 91.16  
##  3rd Qu.:95.59   3rd Qu.:95.73   3rd Qu.:94.58   3rd Qu.: 95.29  
##  Max.   :99.24   Max.   :99.24   Max.   :99.75   Max.   :100.00  
## 
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats   1.0.0     ✔ readr     2.1.4
## ✔ ggplot2   3.5.1     ✔ stringr   1.5.0
## ✔ lubridate 1.9.3     ✔ tibble    3.2.1
## ✔ purrr     1.0.1     ✔ tidyr     1.3.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
Plot.data = pivot_longer(capacity_lac, -country) %>% 
  mutate(name = as.numeric(name),
         value = as.numeric(value))
view(Plot.data)
str(Plot.data)
## tibble [2,460 × 3] (S3: tbl_df/tbl/data.frame)
##  $ country: chr [1:2460] "Mexico" "Mexico" "Mexico" "Mexico" ...
##  $ name   : num [1:2460] 1900 1901 1902 1903 1904 ...
##  $ value  : num [1:2460] 96.2 96.2 96.2 96.2 96.2 ...
summary(Plot.data)
##    country               name          value       
##  Length:2460        Min.   :1900   Min.   : 41.17  
##  Class :character   1st Qu.:1930   1st Qu.: 82.17  
##  Mode  :character   Median :1961   Median : 91.00  
##                     Mean   :1961   Mean   : 88.82  
##                     3rd Qu.:1992   3rd Qu.: 97.46  
##                     Max.   :2022   Max.   :100.00  
##                                    NA's   :24
## Time Series Plot
install.packages("randomcoloR")
## 
## The downloaded binary packages are in
##  /var/folders/rz/h261r9g93pz6tzgqk1tt08_h0000gn/T//RtmpHysJKe/downloaded_packages
library(randomcoloR)

# Generate 20 random colors
random_colors <- randomColor(count = 20)

ggplot(Plot.data, mapping = aes(x= name, y = value, color = country)) +
  geom_point() +  
  geom_line(aes(group = country) +
              scale_color_manual(values = random_colors)) +
  labs (title = "Change in Territorial Control : 1900-2022", x = "Year", y="Territorial Control")
## Warning: Removed 24 rows containing missing values or values outside the scale range
## (`geom_point()`).
## Warning: Removed 5 rows containing missing values or values outside the scale range
## (`geom_line()`).

###with points 

ggplot(Plot.data, mapping = aes(x= name, y = value, color = country)) +
  geom_line(aes(group = country) +
              scale_color_manual(values = random_colors)) +
  labs (title = "Change in Territorial Control : 1900-2022", x = "Year", y="Territorial Control")
## Warning: Removed 5 rows containing missing values or values outside the scale range
## (`geom_line()`).

###w/o points, just lines



#6 creating a matrix 

Offshore_wealth23 <- read_excel("~/Downloads/Offshore financial wealth database october 2023.xlsx", 
                                                              col_types = c("text", "text", "text", 
                                                                            "text", "text", "text", "numeric", 
                                                                            "numeric", "text", "text"))
View(Offshore_wealth23)

matrix.2005 <- Offshore_wealth23 %>%
  filter(regionname =="Latin America & Caribbean", year == "2005") %>%
  select(country_name, value)
  
View(matrix.2005)
summary(matrix.2005)
##  country_name           value         
##  Length:246         Min.   :  0.0000  
##  Class :character   1st Qu.:  0.0000  
##  Mode  :character   Median :  0.0169  
##                     Mean   :  7.4455  
##                     3rd Qu.:  0.8753  
##                     Max.   :340.7983  
##                     NA's   :38
###answer is 340.7983 (Cayman Islands)


matrix.2022 <- Offshore_wealth23 %>%
  filter(regionname =="Latin America & Caribbean", year == "2022") %>%
  select(country_name, value)

View(matrix.2022)
summary(matrix.2022)
##  country_name           value          
##  Length:246         Min.   :  0.00000  
##  Class :character   1st Qu.:  0.00000  
##  Mode  :character   Median :  0.00227  
##                     Mean   :  8.17015  
##                     3rd Qu.:  2.32198  
##                     Max.   :239.00473  
##                     NA's   :37
###answer is 239.00473 (Cayman Islands)




#7 whatever I want