2014年9月19日:過去30日間に発生した地震に関する各種ヒストグラム-世界全体および日本の状況について


Data Source:U.S. Geological Survey http://earthquake.usgs.gov/earthquakes/feed/v1.0/csv.php

Sys.time()
## [1] "2014-09-19 19:22:49 JST"

Package

library(xts) # http://cran.r-project.org/web/packages/xts/xts.pdf
library(ggplot2) # http://cran.r-project.org/web/packages/ggplot2/ggplot2.pdf
library(gridExtra) #http://cran.r-project.org/web/packages/gridExtra/gridExtra.pdf
library(knitr) # http://cran.r-project.org/web/packages/knitr/knitr.pdf
library(googleVis) # http://cran.r-project.org/web/packages/googleVis/googleVis.pdf
library(xtable)

Read Data

data.location=2 #1:local 2:web
data.file="all_month.csv"
if(data.location==1){
username<-Sys.info()['user']
path01<-paste("C:/Users/",username,"/Desktop/Earthquake_Data/",sep="")
setwd(path01)
dataset<-read.table(file=paste(path01,data.file,sep=""),sep=",",header=T,as.is=T,skip=0)
}else{
dataset<-read.csv(paste("http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/",data.file,sep=""),header=T,as.is=T,skip=0) 
}
dataset.j<-dataset[grep("Japan",dataset[,14]),]

Part of Data

head(dataset,1)
##                       time latitude longitude depth  mag magType nst gap
## 1 2014-09-19T09:59:34.750Z    37.68    -121.7  3.22 2.16      md  17 117
##      dmin  rms net         id                  updated
## 1 0.06419 0.22  nc nc72301871 2014-09-19T10:04:08.526Z
##                            place       type
## 1 4km E of Livermore, California earthquake
tail(dataset,1)
##                          time latitude longitude depth mag magType nst gap
## 8985 2014-08-20T10:14:15.690Z    32.64     47.81    10 5.7     mwp  NA  43
##       dmin rms net         id                  updated
## 8985 6.855 0.8  us usb000s4if 2014-09-04T15:53:28.000Z
##                         place       type
## 8985 50km E of Dehloran, Iran earthquake

Map for Earthquake over magnitude 5.0 in the past 30 days

dataset.s<-subset(dataset,5<=dataset[,5])
dataset.s$latlong<-paste(dataset.s$latitude,dataset.s$longitude,sep=":")
dataset.s$jst<-as.POSIXct(sub("Z","",sub("T"," ",dataset.s$time)))+3600*9
dataset.s$info<-paste("Time(UTC)=",dataset.s$time," , UTC+9=",dataset.s$jst,", Depth(km)=",dataset.s$depth,", Mag=",dataset.s$mag," , MagType=",dataset.s$magType,", Place=",dataset.s$place,sep=" ")
gMap<-gvisMap(
dataset.s,"latlong","info",
options=list(
showTip=TRUE, 
showLine=TRUE, 
enableScrollWheel=TRUE,
mapType='terrain', #'hybrid','normal','terrain','satellite'
useMapTypeControl=TRUE
)
)
print(gMap,tag="chart")




Number of Earthquakes in the past 30days by Magnitude

  • Ratio(%)=Japan/World*100
region<-c("","Japan","Indonesia","Mexico","Alaska")
mgt<-c(0,1,2.5,4.5,5.5)
Ecount<-matrix(nrow=length(mgt),ncol=length(region))
for(rrr in 1:length(region)){
r.dataset<-dataset[grep(region[rrr],dataset[,14]),]
for(mmm in 1:length(mgt)){
count<-length(subset(r.dataset,mgt[mmm]<=r.dataset[,5])[,1])
Ecount[mmm,rrr]<-count
}
}
Ecount<-as.data.frame(Ecount,stringsAsFactors=F)
rownames(Ecount)<-paste("over",mgt,sep="")
rownames(Ecount)[1]<-"All"
colnames(Ecount)<-region
colnames(Ecount)[1]<-"World"
Ratio<-signif(Ecount$Japan/Ecount$World*100,digits=2)
Ecount<-cbind(Ecount,Ratio)
Ecount<-Ecount[,c(1,2,6,3,4,5)]
print(xtable(Ecount),type="html")


World Japan Ratio Indonesia Mexico Alaska
All 8930 44 0.49 55 66 3614
over1 5865 44 0.75 55 66 2563
over2.5 1255 44 3.50 55 33 285
over4.5 384 36 9.40 42 11 10
over5.5 31 2 6.50 4 1 0

Histogram

bw=c(5,5,10,0.1)
for(rrr in 1:length(region)){
r.dataset<-dataset[grep(region[rrr],dataset[,14]),]
if(rrr==1){PlotTitle<-"World"}else{PlotTitle<-region[rrr]}
for(ppp in 1:4){ 
switch(ppp,
g<-ggplot(r.dataset,aes(x=latitude)),
g<-ggplot(r.dataset,aes(x=longitude)),
g<-ggplot(r.dataset,aes(x=depth)),
g<-ggplot(r.dataset,aes(x=mag))
)  
g<-g+geom_histogram(alpha=0.2,binwidth=bw[ppp],colour="blue")
g<-g+labs(title=PlotTitle)
g<-g+theme(plot.title=element_text(size=9))
g<-g+theme(axis.title.x=element_text(size=9),axis.title.y=element_text(size=9)) 
g<-g+theme(axis.text.x=element_text(size=9),axis.text.y=element_text(size=9)) 
switch(ppp,
lat<-g,
lon<-g,
dep<-g,
magn<-g
)
}
grid.arrange(lat,lon,dep,magn,nrow=1,ncol=4)
}

plot of chunk unnamed-chunk-7plot of chunk unnamed-chunk-7plot of chunk unnamed-chunk-7plot of chunk unnamed-chunk-7plot of chunk unnamed-chunk-7