library(xts)
library(gdata)
library(ggplot2)
library(grid)
library(Quandl)
load(url("http://statrstart.github.io/data/d2010_2016.RData"))
temp <- tempfile()
download.file("http://www3.boj.or.jp/market/jp/etfreit.zip",temp)
con <- unzip(temp, "2017.xls")
d201701_03 <- read.xls(con,header=F,skip=7)
unlink(temp)
d2017<-d201701_03[,2:5]
names(d2017)<-c("date","ETF","ETF2","REIT")
d2017$ETF[is.na(d2017$ETF)]<-0
d2017$ETF2[is.na(d2017$ETF2)]<-0
d2017$REIT[is.na(d2017$REIT)]<-0
head(d2017) ; tail(d2017)
d2010_2017<-rbind(d2010_2016,d2017)
x <- read.zoo(d2010_2017)
a1<-ggplot(data = fortify(cumsum(x[,1]), melt = TRUE),aes(x = Index, y = Value) ) +
geom_bar(stat="identity",position=position_dodge(),fill=rgb(1,0,0,alpha=0.7)) +
labs(title=paste("日銀買い入れ:累計(ETF) ",d2010_2017[1,"date"],"_",d2010_2017[nrow(d2010_2017),"date"]),
subtitle = "Purchases of ETFs other than those mentioned in ETF(2)", x="", y="")
a1<-a1 + theme_bw(base_size = 11, base_family = "IPAPMincho")
a2<-ggplot(data = fortify(cumsum(x[,2]), melt = TRUE),aes(x = Index, y = Value) ) +
geom_bar(stat="identity",position=position_dodge(),fill=rgb(1,0,0,alpha=0.7)) +
labs(title=paste("日銀買い入れ:累計(ETF(2) ) ",d2010_2017[1,"date"],"_",d2010_2017[nrow(d2010_2017),"date"]),
subtitle = "Purchases of ETFs to support investment in physical and human capital",x="", y="")
a2<-a2 + theme_dark(base_size = 11, base_family = "IPAGothic")
b<-ggplot(data = fortify(cumsum(x[,3]), melt = TRUE),aes(x = Index, y = Value) ) +
geom_bar(stat="identity",position=position_dodge(),fill=rgb(0,0,1,alpha=0.7)) +
labs(title=paste("日銀買い入れ:累計(REIT) ",d2010_2017[1,"date"],"_",d2010_2017[nrow(d2010_2017),"date"]),
caption = "(data : http://www3.boj.or.jp/market/jp/pastetfreit.zip & etfreit.zip ) ",x="", y="")
b<-b + theme_light(base_size = 11, base_family = "TakaoMincho")
grid.newpage()
pushViewport(viewport(layout=grid.layout(3, 1)))
print(a1, vp=viewport(layout.pos.row=1))
print(a2, vp=viewport(layout.pos.row=2))
print(b, vp=viewport(layout.pos.row=3))