library(xts)
library(gdata)
library(ggplot2)
library(grid)
library(quantmod)
library(ggthemes)
load(url("http://statrstart.github.io/data/d2010_2015.RData"))
temp <- tempfile()
download.file("http://www3.boj.or.jp/market/jp/etfreit.zip",temp)
con <- unzip(temp, "2016.xls")
d2016 <- read.xls(con,header=F,skip=8)
unlink(temp)
d2016<-d2016[,2:4]
names(d2016)<-c("date","ETF","REIT")
d2016$ETF[is.na(d2016$ETF)]<-0
d2016$REIT[is.na(d2016$REIT)]<-0
d2010_2016<-rbind(d2010_2015,d2016)
x <- read.zoo(d2010_2016)
a<-ggplot(data = fortify(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="日銀買い入れ(ETF)", x="", y="")
b<-ggplot(data = fortify(x[,2], melt = TRUE),aes(x = Index, y = Value) ) +
geom_bar(stat="identity",position=position_dodge(),fill=rgb(0,0,1,alpha=0.7)) +
labs(title="日銀買い入れ(REIT)", x="", y="")
grid.newpage()
pushViewport(viewport(layout=grid.layout(2, 1)))
print(a, vp=viewport(layout.pos.row=1))
print(b, vp=viewport(layout.pos.row=2))