2014年8月分 日本の消費者物価指数 データ出所:総務省

Sys.time()
## [1] "2014-09-26 16:40:48 JST"

Package

library(ggplot2)
library(scales)

Read Data

username<-Sys.info()['user']
folder.name<-c("R_Data_Read","R_image","R_Data_Write")
path<-paste("C:/Users/",username,"/Desktop",sep="")
for(fff in 1:length(folder.name)){
folder.path<-file.path(path,folder.name[fff])
if(file.exists(folder.path)==F){dir.create(folder.path)}
assign(paste("path",fff,sep=""),folder.path)
}
setwd(path1) #read
file.list<-list()
for(iii in 1:length(dir(path1))){
file.list[[iii]]<-read.table(file=dir(path1)[iii],header=T,sep=",",as.is=T) 
}
#file.select<-menu(dir(path1),title="File(0:Exit)")
file.select<-1
dataset<-file.list[[file.select]]
dataset[,1]<-as.Date(dataset[,1])
colnames(dataset)[1]<-"date"
dataset<-subset(dataset,as.Date("2004/9/1")<=dataset[,1])

Plot

#cpi
ggplot(dataset,aes(x=date,y=dataset[,2]))+geom_bar(stat="identity",position="identity",fill="blue",alpha=0.2,color="black")+scale_x_date(labels=date_format("%y/%m/%d"))+xlab("Date")+ylab("%")+ggtitle("CPI y-y(%)")

plot of chunk unnamed-chunk-4

#core cpi
ggplot(dataset,aes(x=date,y=dataset[,3]))+geom_bar(stat="identity",position="identity",fill="red",alpha=0.2,color="black")+scale_x_date(labels=date_format("%y/%m/%d"))+xlab("Date")+ylab("%")+ggtitle("Core CPI y-y(%)")

plot of chunk unnamed-chunk-4

#corecore cpi
ggplot(dataset,aes(x=date,y=dataset[,6]))+geom_bar(stat="identity",position="identity",fill="green",alpha=0.2,color="black")+scale_x_date(labels=date_format("%y/%m/%d"))+xlab("Date")+ylab("%")+ggtitle("CoreCore CPI y-y(%)")

plot of chunk unnamed-chunk-4

Rank

r.dataset<-dataset[nrow(dataset),c(2:ncol(dataset))]
r.dataset<-t(r.dataset)
colnames(r.dataset)<-"latest"
r.dataset<-data.frame(item=rownames(r.dataset),r.dataset,row.names=NULL)
#head(r.dataset)
#tail(r.dataset)
rrr<-order(r.dataset[,2])
r.dataset<-r.dataset[rrr,]
#head(r.dataset)
#tail(r.dataset)
rownames(r.dataset)<-c(1:nrow(r.dataset))
#head(r.dataset)
#tail(r.dataset)
r.dataset[,1]<-ordered(r.dataset[,1],levels=r.dataset[,1][1:length(r.dataset[,1])])
g<-ggplot(r.dataset,aes(x=item,y=latest))
g<-g+geom_bar(stat="identity",position="identity",fill="grey",alpha=0.5,color="black")
g+geom_text(aes(label=r.dataset[,2]),hjust=-0.5)+coord_flip() #vjust=-0.5

plot of chunk unnamed-chunk-5