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


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

Sys.time()
## [1] "2014-09-23 19:43:13 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-23T09:57:29.880Z    32.56    -115.7  9.22 2.1      ml  23 131
##     dmin  rms net         id                  updated
## 1 0.1007 0.38  ci ci37043695 2014-09-23T10:01:23.690Z
##                         place       type
## 1 8km WSW of Progreso, Mexico earthquake
tail(dataset,1)
##                          time latitude longitude depth mag magType nst gap
## 8647 2014-08-24T10:30:36.000Z    61.51    -146.7  31.5 1.4      ml  NA  NA
##      dmin  rms net         id                  updated
## 8647   NA 0.68  ak ak11366711 2014-09-05T20:49:21.058Z
##                           place       type
## 8647 45km NNW of Valdez, Alaska 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 8610 42 0.49 56 64 3326
over1 5596 42 0.75 56 64 2359
over2.5 1201 42 3.50 56 32 237
over4.5 387 35 9.00 43 12 8
over5.5 28 2 7.10 5 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