Sys.time()
## [1] "2014-10-28 00:53:14 JST"
dataset<-list()
plot.title<-list()
bw<-list()
chk<-list()
file.name<-c(
"dev_temp_japan.txt", #1
"dev_temp_world.txt", #2
"typhoon_japan.txt",  #3
"ryori_co2.txt",      #4
"ryori_methane.txt",  #5
"tsukuba_ozone.txt",  #6
"tsukuba_uv.txt",     #7
"yellow_dust.txt"     #8
)
username<-Sys.info()['user']
path<-paste("C:/Users/",username,"/Desktop/meteorological/",sep="")
setwd(path)
for(iii in 1:length(file.name)){
tmp.0<-read.table(file=paste(path,file.name[iii],sep=""),header=F,stringsAsFactors=F,sep="\t",na.strings=c("NA","-",""),encoding="UTF-8")
tmp.1<-tmp.0[,-1]
chk[[iii]]<-iii
if(grepl("dev_temp_japan",file.name[[iii]])==T){
bw[[iii]]<-0.1
year.start<-as.Date("1898/1/1")
year.end<-as.Date("2014/9/1")
tmp.2<-as.vector(t(tmp.1))#as.vector(as.matrix(tmp))
plot.title[[iii]]<-"mo.Ave.Temp.Dep.Japan"
}else if(grepl("dev_temp_world",file.name[[iii]])==T){
bw[[iii]]<-0.1
year.start<-as.Date("1891/1/1")
year.end<-as.Date("2014/9/1")
tmp.2<-as.vector(t(tmp.1))
plot.title[[iii]]<-"mo.Ave.Temp.Dep.World"
}else if(grepl("typhoon_japan",file.name[[iii]])==T){
bw[[iii]]<-1
year.start<-as.Date("1951/1/1")
year.end<-as.Date("2014/10/1")
tmp.1<-tmp.1[,-13]
tmp.2<-as.vector(t(rev(tmp.1)))
plot.title[[iii]]<-"Typhoon.Incidence"
}else if(grepl("ryori_co2",file.name[[iii]])==T){
bw[[iii]]<-10
year.start<-as.Date("1987/1/1")
year.end<-as.Date("2014/4/1")
FUN.1<-function(x) gsub("[(]","",x)
FUN.2<-function(x) gsub("[)]","",x)
FUN.3<-function(x) gsub("--","",x)
FUN.4<-function(x) as.numeric(x)
tmp.1<-apply(tmp.1,2,FUN.1)
tmp.1<-apply(tmp.1,2,FUN.2)
tmp.1<-apply(tmp.1,2,FUN.3)
tmp.1<-apply(tmp.1,2,FUN.4)
tmp.2<-as.vector(t(tmp.1))
plot.title[[iii]]<-"CO2.ppm"
}else if(grepl("ryori_methane",file.name[[iii]])==T){
bw[[iii]]<-1
year.start<-as.Date("1991/1/1")
year.end<-as.Date("2014/4/1")
FUN.1<-function(x) gsub("[(]","",x)
FUN.2<-function(x) gsub("[)]","",x)
FUN.3<-function(x) gsub("--","",x)
FUN.4<-function(x) as.numeric(x)
tmp.1<-apply(tmp.1,2,FUN.1)
tmp.1<-apply(tmp.1,2,FUN.2)
tmp.1<-apply(tmp.1,2,FUN.3)
tmp.1<-apply(tmp.1,2,FUN.4)
tmp.2<-as.vector(t(tmp.1))
plot.title[[iii]]<-"Methane"
}else if(grepl("tsukuba_ozone",file.name[[iii]])==T){
bw[[iii]]<-10
year.start<-as.Date("1957/1/1")
year.end<-as.Date("2014/9/1")
tmp.1<-tmp.1[,-13]
tmp.2<-as.vector(t(rev(tmp.1)))
plot.title[[iii]]<-"Ozone"
}else if(grepl("tsukuba_uv",file.name[[iii]])==T){
bw[[iii]]<-1
year.start<-as.Date("2005/1/1")
year.end<-as.Date("2014/9/1")
tmp.2<-as.vector(t(rev(tmp.1)))
plot.title[[iii]]<-"UV"
}else if(grepl("yellow_dust",file.name[[iii]])==T){
bw[[iii]]<-1
year.start<-as.Date("1967/1/1")
year.end<-as.Date("2014/9/1")
tmp.1<-tmp.1[,-13]
tmp.2<-as.vector(t(rev(tmp.1)))
plot.title[[iii]]<-"Yellow.Dust"
}
seq.type<-"month"
date<-seq(as.Date(year.start),by=seq.type,length.out=length(tmp.2))
if(chk[[iii]]!=3 & chk[[iii]]!=6 & chk[[iii]]!=7 & chk[[iii]]!=8){
dataset[[iii]]<-data.frame(date,tmp.2)
}
else{
dataset[[iii]]<-data.frame(date,rev(tmp.2))
}
dataset[[iii]]<-subset(dataset[[iii]],year.start<=dataset[[iii]][,1] & dataset[[iii]][,1]<=year.end)
if(chk[[iii]]==8){
dataset[[iii]][,2]<-as.numeric(as.character(dataset[[iii]][,2])) #convert factor to numeric
}
if(chk[[iii]]!=4 & chk[[iii]]!=5){
dataset[[iii]][is.na(dataset[[iii]])]<-0
}
colnames(dataset[[iii]])[2]<-plot.title[[iii]]
if(iii==1){dataset[[(length(file.name)+1)]]<-dataset[[iii]]}else{
(dataset[[(length(file.name)+1)]]<-merge(dataset[[(length(file.name)+1)]],dataset[[iii]],by="date"))
}
colnames(dataset[[(length(file.name)+1)]])[iii+1]<-plot.title[[iii]]
}

Plot time series and histogram

options(width=850)
diff.date<-365*20
first.date<-Sys.Date()-diff.date
last.date<-Sys.Date()-0
plots<-list()
n.col<-2
for(ppp in 1:2){#1 timeseries 2 histogram
for(iii in 1:(length(file.name))){
tmp<-dataset[[iii]]
tmp<-subset(tmp,first.date<=tmp[,1])
date.s<-format(tmp[,1][1],"%Y/%b")
date.e<-format(tmp[,1][nrow(tmp)],"%Y/%b")
colnames(tmp)[2]<-"value"
if(ppp==1){
g<-ggplot(tmp,aes(x=date,y=value))
if(chk[[iii]]==1 | chk[[iii]]==2 | chk[[iii]]==3 | chk[[iii]]==8){
g<-g+geom_bar(stat="identity",position="identity",fill="blue",alpha=0.2,color="black")
}else{
g<-g+geom_line()
}
if(chk[[iii]]!=3){
g<-g+geom_smooth(method=lm)
g<-g+geom_smooth(method=loess,color="red")
}
g<-g+scale_x_date(labels=date_format("%Y/%b"))
}else{
g<-ggplot(tmp,aes(x=value))
g<-g+geom_histogram(binwidth=bw[[iii]],fill="grey",alpha=0.5,color="black")
}
g<-g+ggtitle(paste(plot.title[[iii]],"\n",date.s,"-",date.e))
plots[[iii]]<-g
}
multiplot(plotlist=plots,cols=n.col)
}

Sumamry

options(width=850)
par(mfrow=c(ceiling(length(file.name)/n.col),n.col),mar=c(3,3,3,3))
for(iii in 1:(length(file.name))){
tmp<-dataset[[iii]]
date.s<-format(tmp[,1][1],"%Y/%b")
date.e<-format(tmp[,1][nrow(tmp)],"%Y/%b")
cat(paste(plot.title[[iii]],"",date.s,"-",date.e,"\n"))
print(summary(tmp[,2]))
cat("\n\n")
}
## mo.Ave.Temp.Dep.Japan  1898/1 - 2014/9 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## -3.3400 -1.1400 -0.5100 -0.5082  0.1100  2.3300 
## 
## 
## mo.Ave.Temp.Dep.World  1891/1 - 2014/9 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## -1.3200 -0.5400 -0.3400 -0.3338 -0.1300  0.4300 
## 
## 
## Typhoon.Incidence  1951/1 - 2014/10 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   0.000   0.000   1.000   2.179   4.000  10.000 
## 
## 
## CO2.ppm  1987/1 - 2014/4 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   344.8   361.8   372.4   374.1   387.0   407.0       1 
## 
## 
## Methane  1991/1 - 2014/4 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##    1744    1838    1858    1855    1878    1921      38 
## 
## 
## Ozone  1957/1 - 2014/9 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##     0.0   284.0   309.0   309.6   337.0   392.0 
## 
## 
## UV  2005/1 - 2014/9 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    1.50    2.40    4.30    4.28    5.80    8.20 
## 
## 
## Yellow.Dust  1967/1 - 2014/9 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   0.000   0.000   0.000   1.773   2.000  21.000

Table

tmp<-dataset[[length(file.name)+1]]
tmp[,1]<-format(tmp[,1],"%Y-%b")
gTable<-gvisTable(tmp)
print(gTable,tag="chart")

Data Source/Reference