# Minimal working example: Fetch data from the ECB statistical warehouse
# install package if necessary
# install.packages("pdfetch") # comment/ uncomment to run
# install.packages("ggplot2") # comment/ uncomment to run
# install.packages("reshape2") # comment/ uncomment to run
# Load library
require("pdfetch")
## Loading required package: pdfetch
## Warning: package 'pdfetch' was built under R version 3.2.3
require("ggplot2")
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.2.3
require("reshape2")
## Loading required package: reshape2
# Estonia, Not specified, Credit Institutions (as defined in the Community Law) reference sector - Herfindahl index for Credit institutions (CIs) total assets - Domestic (home or reference area) counterpart
# Series Key SSI.A.EE.122C.H10.X.U6.Z0Z.Z
EE_HHI<-tryCatch(pdfetch_ECB("SSI.A.EE.122C.H10.X.U6.Z0Z.Z"),
error = function(e) {},
warning = function(w) {}
)
## No encoding supplied: defaulting to UTF-8.
# Display data Series
(EE_HHI)
## SSI.A.EE.122C.H10.X.U6.Z0Z.Z
## 1998-12-31 0.3891
## 1999-12-31 0.3978
## 2000-12-31 0.4037
## 2001-12-31 0.4067
## 2002-12-31 0.4028
## 2003-12-31 0.3943
## 2004-12-31 0.3887
## 2005-12-31 0.4039
## 2006-12-31 0.3593
## 2007-12-31 0.3410
## 2008-12-31 0.3120
## 2009-12-31 0.3090
## 2010-12-31 0.2929
## 2011-12-31 0.2613
## 2012-12-31 0.2493
## 2013-12-31 0.2483
## 2014-12-31 0.2445
# Check object class
class(EE_HHI)
## [1] "xts" "zoo"
str(EE_HHI)
## An 'xts' object on 1998-12-31/2014-12-31 containing:
## Data: num [1:17, 1] 0.389 0.398 0.404 0.407 0.403 ...
## - attr(*, "dimnames")=List of 2
## ..$ : NULL
## ..$ : chr "SSI.A.EE.122C.H10.X.U6.Z0Z.Z"
## Indexed by objects of class: [Date] TZ: UTC
## xts Attributes:
## List of 1
## $ origin: chr "1970-01-01"
# plot data series
# convert to ts object for easier melting
EE_HHI.ts<-as.ts(EE_HHI, start = c(1998,1))
# Melt
melt_EE_HHI<-melt(data.frame(time = as.numeric(time(EE_HHI.ts)), EE_HHI.ts), id.vars="time")
# ggplot
p_EE_HHI<-ggplot() +
geom_line(data=melt_EE_HHI, mapping=aes(x=time, y=value, colour= variable, linetype =variable),
,size=1.0) +
# scale_colour_manual(values=c("red"))+ # this is important: without a manual colour scale the color = "Variable name" does not get plotted on the legend
scale_x_continuous(breaks = seq(1998, 2014, by = 1))+
scale_y_continuous(breaks = seq(0.05, 1, by = 0.05))+ # define axis ticks behaviour
# minor_breaks = seq(0, 180, 50)) + #define axis gridline behaviour
theme(legend.title=element_blank(),
# panel.grid.major=element_blank(), # Hide all the gridlines
panel.grid.minor=element_blank(), # Hide just the minor gridlines
legend.justification=c(0,0), legend.position=c(0.5,0.03),
legend.background = element_rect(size=1, fill=alpha(0.9)), # transparent legend
legend.title=element_text(size=14), # adapt size so it fits as tikz on full screen beamer
legend.key.size = unit(1, "cm"))+ # adapt size so it fits as tikz on full screen beamer
xlab("") +
ylab("") # +
# call ggplot
p_EE_HHI
