First load up the tidyverse
library(tidyverse)
## ── Attaching packages ───────────────────────────────────────────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.0 ✓ purrr 0.3.3
## ✓ tibble 2.1.3 ✓ dplyr 0.8.5
## ✓ tidyr 1.0.2 ✓ stringr 1.4.0
## ✓ readr 1.3.1 ✓ forcats 0.5.0
## ── Conflicts ──────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
Then read in the data, rates.csv and name it rates
# ___ <- read_csv("data/___")
rates <- read_csv(here::here("data/rates.csv"))
## Parsed with column specification:
## cols(
## .default = col_double(),
## date = col_date(format = "")
## )
## See spec(...) for full column specifications.
head(rates)
## # A tibble: 6 x 169
## date AED AFN ALL AMD ANG AOA ARS AUD AWG AZN BAM
## <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 2017-06-20 3.67 68.1 119. 481. 1.78 166. 16.1 1.32 1.80 1.7 1.76
## 2 2017-06-21 3.67 68.1 119. 480. 1.78 166. 16.2 1.32 1.79 1.7 1.75
## 3 2017-06-22 3.67 68.1 119. 481. 1.78 166. 16.1 1.33 1.79 1.7 1.75
## 4 2017-06-23 3.67 68.1 118. 479. 1.78 166. 16.2 1.32 1.80 1.7 1.75
## 5 2017-06-24 3.67 68.1 118. 479. 1.78 166. 16.2 1.32 1.80 1.7 1.75
## 6 2017-06-25 3.67 67.9 118. 479. 1.78 166. 16.1 1.32 1.80 1.7 1.75
## # … with 157 more variables: BBD <dbl>, BDT <dbl>, BGN <dbl>, BHD <dbl>,
## # BIF <dbl>, BMD <dbl>, BND <dbl>, BOB <dbl>, BRL <dbl>, BSD <dbl>,
## # BTC <dbl>, BTN <dbl>, BWP <dbl>, BYN <dbl>, BZD <dbl>, CAD <dbl>,
## # CDF <dbl>, CHF <dbl>, CLF <dbl>, CLP <dbl>, CNH <dbl>, CNY <dbl>,
## # COP <dbl>, CRC <dbl>, CUC <dbl>, CUP <dbl>, CVE <dbl>, CZK <dbl>,
## # DJF <dbl>, DKK <dbl>, DOP <dbl>, DZD <dbl>, EGP <dbl>, ERN <dbl>,
## # ETB <dbl>, EUR <dbl>, FJD <dbl>, FKP <dbl>, GBP <dbl>, GEL <dbl>,
## # GGP <dbl>, GHS <dbl>, GIP <dbl>, GMD <dbl>, GNF <dbl>, GTQ <dbl>,
## # GYD <dbl>, HKD <dbl>, HNL <dbl>, HRK <dbl>, HTG <dbl>, HUF <dbl>,
## # IDR <dbl>, ILS <dbl>, IMP <dbl>, INR <dbl>, IQD <dbl>, IRR <dbl>,
## # ISK <dbl>, JEP <dbl>, JMD <dbl>, JOD <dbl>, JPY <dbl>, KES <dbl>,
## # KGS <dbl>, KHR <dbl>, KMF <dbl>, KPW <dbl>, KRW <dbl>, KWD <dbl>,
## # KYD <dbl>, KZT <dbl>, LAK <dbl>, LBP <dbl>, LKR <dbl>, LRD <dbl>,
## # LSL <dbl>, LYD <dbl>, MAD <dbl>, MDL <dbl>, MGA <dbl>, MKD <dbl>,
## # MMK <dbl>, MNT <dbl>, MOP <dbl>, MRO <dbl>, MUR <dbl>, MVR <dbl>,
## # MWK <dbl>, MXN <dbl>, MYR <dbl>, MZN <dbl>, NAD <dbl>, NGN <dbl>,
## # NIO <dbl>, NOK <dbl>, NPR <dbl>, NZD <dbl>, OMR <dbl>, PAB <dbl>, …
Now plot the data:
dateAUDggplot(rates,
# aes(x = ___,
# y = ___)) +
aes(x = date,
y = AUD)) +
geom_line()
Make a subset of the data that includes the following columns:
dateAUDGBPJPYCNYCADrates_sub <- rates %>%
# select(___,
# ___,
# ___,
# ___,
# ___,
# ___)
select(date,
AUD,
GBP,
JPY,
CNY,
CAD)
rates_sub
## # A tibble: 24 x 6
## date AUD GBP JPY CNY CAD
## <date> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 2017-06-20 1.32 0.792 111. 6.83 1.33
## 2 2017-06-21 1.32 0.789 111. 6.83 1.33
## 3 2017-06-22 1.33 0.789 111. 6.83 1.32
## 4 2017-06-23 1.32 0.786 111. 6.84 1.33
## 5 2017-06-24 1.32 0.786 111. 6.84 1.33
## 6 2017-06-25 1.32 0.785 111. 6.83 1.33
## 7 2017-06-26 1.32 0.786 112. 6.84 1.33
## 8 2017-06-27 1.32 0.780 112. 6.81 1.32
## 9 2017-06-28 1.31 0.773 112. 6.80 1.30
## 10 2017-06-29 1.30 0.769 112. 6.79 1.30
## # … with 14 more rows
Now pivot the data into long form, where:
names_to is currencyvalues_to is raterates_long <- rates_sub %>%
pivot_longer(cols = -date,
names_to = "currency",
values_to = "rate")
# names_to = ___,
# values_to = ___)
rates_long
## # A tibble: 120 x 3
## date currency rate
## <date> <chr> <dbl>
## 1 2017-06-20 AUD 1.32
## 2 2017-06-20 GBP 0.792
## 3 2017-06-20 JPY 111.
## 4 2017-06-20 CNY 6.83
## 5 2017-06-20 CAD 1.33
## 6 2017-06-21 AUD 1.32
## 7 2017-06-21 GBP 0.789
## 8 2017-06-21 JPY 111.
## 9 2017-06-21 CNY 6.83
## 10 2017-06-21 CAD 1.33
## # … with 110 more rows
Now plot the currency rates
date on the x axisrate on the y axisggplot(rates_long,
#% aes(x = ___,
#% y = ___)) +
aes(x = date,
y = rate)) +
geom_line() +
facet_wrap(~currency, # facetted by currency
ncol = 1,
scales = "free_y")
Describe the similarities and differences between the currencies.