########################################## # Graphical Analysis: Wyoming's Economy # ########################################## # Install packages #install.packages("fpp3", dependencies = TRUE) #install.packages("fable", dependencies = TRUE) #install.packages("ggplot2", dependencies = TRUE) #install.packages("tidyverse", dependencies = TRUE) #install.packages("GGally", dependencies = TRUE) # Load packages library(readxl) library(fpp3) library(tsibble) library(tsibbledata) library(tidyverse) library(fable) library(dplyr) library(lubridate) library(ggplot2) library(GGally) # Read in dataset setwd("C:/Documents/Classes/Econ4115/Code") wyoeco <- read_excel("Wyo_Econ.xlsx", sheet = 2, col_names = TRUE) head(wyoeco) # Shows the first 6 lines of the file tail(wyoeco) # Shows the last 6 lines of the file # Store data1 as tsibble object in R wyoeco1 <- wyoeco %>% filter(Year >= 1975) %>% as_tsibble(index = Year) ##################### # Unemployment Rate # ##################### # Regular time series plot of the Unemployment Rate using autoplot wyoeco1 %>% autoplot(UEMPR) + ggtitle("Wyoming Unemployment Rate") + ylab("Unemployment Rate") + xlab("Time") # Plot relationship between Wyoming's Unemployment Rate and Coal Prices wyoeco1 %>% ggplot(aes(x = COAL, y = UEMPR)) + geom_point() + ylab("Unemployment Rate") + xlab("Coal Price") # Lag plot wyoeco1 %>% gg_lag(UEMPR, geom = "point") # Autocorrelation Function (ACF) plot wyoeco1 %>% ACF(UEMPR, lag_max = 20) %>% autoplot() ############### # Coal Prices # ############### # Plot the Coal Price using autoplot wyoeco1 %>% autoplot(COAL) + ggtitle("Coal Prices") + ylab("$ per metric ton") + xlab("Time") # Lag plot wyoeco1 %>% gg_lag(COAL, geom = "point") # Autocorrelation Function (ACF) plot wyoeco1 %>% ACF(COAL, lag_max = 10) %>% autoplot() ############### # Tax Revenue # ############### # Plot WY Total Tax Revenue using autoplot wyoeco1 %>% autoplot(TREV) + ggtitle("Tax Revenue") + ylab("Dollars") + xlab("Time") # Lag plot wyoeco1 %>% gg_lag(TREV, geom = "point") # Autocorrelation Function (ACF) plot wyoeco1 %>% ACF(TREV, lag_max = 10) %>% autoplot() ######################## # Pairwise Plot Matrix # ######################## wyoeco1 %>% select(UEMPR, COAL, TREV) %>% GGally::ggpairs(columns = 1:3)