-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInflation Script.R
More file actions
64 lines (43 loc) · 1.72 KB
/
Copy pathInflation Script.R
File metadata and controls
64 lines (43 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
library(readr)
library(dplyr)
library(sqldf)
library(ggplot2)
library(tibble)
#########
#Load in and select data
#########
inflation <- read_csv(".../inflation_consumer_prices.csv")
inflation <- inflation_consumer_prices
inflation <- rename(inflation, "Country" = "Country Name", "Code"= "Country Code", "IndicatorN" = "Indicator Name", "IndicatorC" = "Indicator Code")
Venezuela <- sqldf("SELECT * FROM inflation
WHERE Country = 'Venezuela, RB';")
###########
# Transpose data for time series analysis
##########
Venezuela <- select(Venezuela, -Country, -Code, -IndicatorN, -IndicatorC)
Venezuela <- t(Venezuela)
Venezuela <- as.data.frame(Venezuela, stringsAsFactors=F)
#add a new index to transposed data
Venezuela <- rownames_to_column(Venezuela, "Year")
colnames(Venezuela)[2] <- "Inflation_Rate"
#Select data starting from 2007
Venezuela <- sqldf("SELECT * FROM Venezuela
WHERE Year >= 2007;")
#I added a value of 1087.53 for 2017 using "fix(Venezuela)" command
#set Year to Date
Venezuela$Year <- as.Date(Venezuela$Year, "%Y")
#set Inflation rate to numeric
Venezuela$Inflation_Rate <- as.numeric(as.character(Venezuela$Inflation_Rate))
#######
#Plot inflation data
#######
ggplot(Venezuela, aes(Year, Inflation_Rate, group=1))+
geom_line(color='red',size=1.5)+
geom_point(size=2)+
ylim(0,max(Venezuela$Inflation_Rate))+
ylab("Percent Inflation")+
theme(panel.background = element_blank())+
theme(panel.grid.major.y = element_line(color = 'grey'))+
ggtitle("Venezuelan Inflation", subtitle = "Source: World Bank")+
theme(plot.title = element_text(hjust = 0.5))+
theme(plot.subtitle = element_text(hjust = 0.5))