Overview

Below, I’ve created a sample “vignette” that shows the versatility of the Tidyverse package with a dataset. To do this, I’ve pulled a dataset from Kaggle that tracks monthly gold prices.

# read in the data
gold <- read_csv("https://raw.githubusercontent.com/evanmclaughlin/ECM607/master/gold_annual.csv")
## Parsed with column specification:
## cols(
##   Date = col_character(),
##   Price = col_double()
## )
head(gold)
## # A tibble: 6 x 2
##   Date    Price
##   <chr>   <dbl>
## 1 1950-12  34.7
## 2 1951-12  34.7
## 3 1952-12  34.8
## 4 1953-12  34.8
## 5 1954-12  35.0
## 6 1955-12  35.0

There’s not much to this dataset. Just the December of each year and average price of that month dating back to the beginning of the year in 1950. Let’s see if we can extract anything of value.

summary(gold)
##      Date               Price        
##  Length:70          Min.   :  34.66  
##  Class :character   1st Qu.:  35.28  
##  Mode  :character   Median : 320.80  
##                     Mean   : 412.78  
##                     3rd Qu.: 458.94  
##                     Max.   :1687.34
# let's use ggplot to visualize the data in a way that might help us spot any spikes / dips in price and formulate hypotheses about the catalysts for these swings.

g <- ggplot(gold, aes(x=Date, y=Price)) + geom_point() + labs(title = "Price of Gold Over Time", x = "Year", y = "Price") + geom_smooth(method=lm, color = "black")

g + theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
## `geom_smooth()` using formula 'y ~ x'

It seems that gold’s price was especially stable prior to 1970. Let’s cut out the prior to then and drill down on the remaining years using dplyr.

gold_filt <- gold %>%
  filter(Date > 1969) 

g2 <- ggplot(gold_filt, aes(x=Date, y=Price)) + geom_point() + labs(title = "Price of Gold Over Time", x = "Year", y = "Price") + geom_smooth(method=lm, color = "black")

g2 + theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
## `geom_smooth()` using formula 'y ~ x'

The US experienced a good bit of inflation in the late 70s, and it looks as though gold served as a safe harbor during this time, as prices spiked. It also looks as though gold surged on a flight to quality during the financial crisis and has remained at historic highs since. Why? Well, while the US hasn’t experienced inflation in the traditional sense, the largescale Quantitative Easing embarked upon by the Federal Reserve and Central Banks around the world has nonetheless stimulated the global demand for gold. A similar story is playing out in the crypto space.