library(quantmod)
library(ggplot2)
library(reshape2)
library(grid)
library(gridExtra)
getSymbols("DEXJPUS", src = "FRED")
DY <- DEXJPUS["1999::",]
DYm<-apply.monthly(DY,mean,na.rm=T)
DY<-as.xts(coredata(DYm),as.yearmon(index(DYm)))
getSymbols("NIKKEI225",src="FRED")
nikkei<- NIKKEI225["1999::",]
nikkeim<-apply.monthly(nikkei,mean,na.rm=T)
nikkei<-as.xts(coredata(nikkeim),as.yearmon(index(nikkeim)))
getSymbols("JPNASSETS",src="FRED")
jpa<- JPNASSETS["1999::",]
JB<-as.xts(coredata(jpa),as.yearmon(index(jpa)))
dat3<-merge(DY,nikkei,JB,all=T)
xtsplot2<-function(x) {
library(ggplot2)
library(reshape2)
data<-data.frame(date=index(x),coredata(x))
data.melt <- melt(data,id.vars=c("date"),measure.vars=c(colnames(data[2:ncol(data)])))
ggplot(data.melt, aes(x=as.Date(date),y=value,colour=variable,group=variable)) + geom_line(colour = "blue",size =0.5,linetype=1,alpha = 1)+labs(x="", y="")
}
p1<-xtsplot2(dat3[,1])+ labs(title="USD/Yen")
p2<-xtsplot2(dat3[,2])+ labs(title="NIKKEI225")
p3<-xtsplot2(dat3[,3])+ labs(title="Bank of Japan: Total Assets for Japan")
grid.arrange(p1,p2,p3,ncol=1,nrow=3)