日本の国際収支(貿易収支)2014年7月分 出所:日本銀行

13カ月連続で輸入超過。
日本の貿易収支

#各種条件設定
path01<-paste("C:/Users/",username,"/Desktop/R_Data_Read/",sep="")
path02<-paste("C:/Users/",username,"/Desktop/R_Graph/",sep="")
path03<-paste("C:/Users/",username,"/Desktop/R_Data_Write/",sep="")
setwd(path01)
#パッケージ読込
library(urca) #ca.po()
library(tseries)
library(forecast)
library(MASS) #truehist()
library(lmtest) #dwtest
library(systemfit)
#フォルダ内のファイルを変数化
for(iii in 1:length(dir(path01)))
{#sepia
tmp<-read.table(file=dir(path01)[iii],header=TRUE,sep=",")
#オリジナルデータが2014/09形式の場合
tmp[,1]<-paste(as.integer(substr(tmp[,1],1,4)),"/",as.integer(substr(tmp[,1],6,7)),"/1",sep="")
tmp[,1]<-as.Date(tmp[,1])
colnames(tmp)[1]<-"date" #小文字
assign(paste("dataset",iii,sep=""),tmp)
cat(paste("dataset",iii,"\n",sep=""))
print(head(tmp))
print(tail(tmp))
}#sepia
##################################################
dataset1[,5]<-sign(dataset1[,2])#冗長となるが今回は一旦符号としてフレームに加える
dataset1[,6]<-10^-10 #dummy 
dataset1[,7]<-10^-10 #dummy
colnames(dataset1)[5]<-"sign" 
colnames(dataset1)[6]<-"yy Exports"
colnames(dataset1)[7]<-"yy Imports"
head(dataset1)
for(nnn in 1:length(dataset1[,5]))
{#blue
if(dataset1[,5][nnn]==-1){dataset1[,5][nnn]<-2}
if(dataset1[,5][nnn]==1){dataset1[,5][nnn]<-4}
if(13<=nnn)
{
dataset1[,6][nnn]<-(dataset1[,3][nnn]-dataset1[,3][nnn-12])/dataset1[,3][nnn-12]*100
dataset1[,7][nnn]<-(dataset1[,4][nnn]-dataset1[,4][nnn-12])/dataset1[,4][nnn-12]*100
}
}#blue
dataset1<-subset(dataset1,as.Date("2013/1/1")<=dataset1[,1])
Date<-dataset1[,1]
Goods.Net.balance<-dataset1[,2]
Goods.Exports<-dataset1[,3]/(10^4)
Goods.Imports<-dataset1[,4]/(10^4)
yyExports<-dataset1[,6]
yyImports<-dataset1[,7]
setwd(path02)
png(file="日本の貿易収支.png",width=900,height=900)
par(mar=c(5,5,5,5),ps=20,cex.axis=1,cex.lab=1,cex.main=1,cex.sub=1)
layout(matrix(c(1,2,3,1,4,5),nrow=3))
barplot(names.arg=format(Date,"%Y%m"),Goods.Net.balance,main=paste(dir(path01)[1],"日本の国際収支(貿易収支) 出所:日本銀行 1996年1月-2014年7月 単位:億円"),col=dataset1[,5])
barplot(names.arg=format(Date,"%Y%m"),Goods.Exports,main="貿易輸出 単位:兆円",col=4,ylim=c(0,10))
barplot(names.arg=format(Date,"%Y%m"),Goods.Imports,main="貿易輸入 単位:兆円",col=2,ylim=c(0,10))
barplot(names.arg=format(Date,"%Y%m"),yyExports,main="前年同月比:貿易輸出 単位:%")
barplot(names.arg=format(Date,"%Y%m"),yyImports,main="前年同月比:貿易輸入 単位:%")
dev.off()
head(dataset1)