2014年9月19日:過去30日間に発生した地震の3Dマップ:世界全体と日本:深さとマグニチュード

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

Sys.time()
## [1] "2014-09-19 14:21:29 JST"

Package

#install.packages("scatterplot3d", dependencies=T)
#install.packages("lattice", dependencies=T)
#install.packages("rgl", dependencies=T)
#install.packages("knitr", dependencies=T)
#install.packages("maps", dependencies=T)
#install.packages("ggplot2", dependencies=T)
library(scatterplot3d) # http://cran.r-project.org/web/packages/scatterplot3d/vignettes/s3d.pdf
library(lattice)
library(rgl)
library(knitr)
library(maps) # http://cran.r-project.org/web/packages/maps/maps.pdf
library(ggplot2) # http://cran.r-project.org/web/packages/ggplot2/ggplot2.pdf

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) 
}

Part of Data

head(dataset,1)
##                       time latitude longitude depth  mag magType nst gap
## 1 2014-09-19T04:50:36.260Z    33.83    -117.7 10.31 0.99      ml  13 147
##      dmin  rms net         id                  updated
## 1 0.06087 0.17  ci ci37042087 2014-09-19T04:54:31.030Z
##                            place       type
## 1 10km WSW of Corona, California earthquake
tail(dataset,1)
##                          time latitude longitude depth mag magType nst
## 9012 2014-08-20T05:10:51.900Z    37.64      -119   7.9 0.4      Md  24
##       gap    dmin  rms net         id                  updated
## 9012 64.8 0.01797 0.05  nc nc72280476 2014-08-23T02:00:31.782Z
##                                    place       type
## 9012 1km SE of Mammoth Lakes, California earthquake

3Dplot

for(iii in 1:2){
if(iii==2){
dataset<-dataset[grep("Japan",dataset[,14]),]
text<-"Only Japan"}else{text<-"Entire World"}
Latitude.degree<-dataset$latitude
Longitude.degree<-dataset$longitude
Depth.km<-(-1)*dataset$depth
Magnitude<-dataset$mag
ang<-c(100)
for(ddd in 1:length(ang)){
scatterplot3d(y=Latitude.degree,x=Longitude.degree,z=Depth.km,angle=ang[ddd],type="h",lwd="1",scale.y=1,color=4,main=paste(text,"-Depth(km)",sep=""))
scatterplot3d(y=Latitude.degree,x=Longitude.degree,z=Magnitude,angle=ang[ddd],type="h",lwd="1",scale.y=1,color=4,main=paste(text,"-Magnitude",sep=""))
#plot3d(y=Latitude.degree,x=Longitude.degree,z=Depth.km,main=text)
#writeWebGL(width=500, height=550)
}
}

plot of chunk unnamed-chunk-5plot of chunk unnamed-chunk-5plot of chunk unnamed-chunk-5plot of chunk unnamed-chunk-5

maps

world.map<-map("world")
# http://cran.r-project.org/web/packages/maps/maps.pdf#page=8
str(world.map)
## List of 4
##  $ x    : num [1:15871] -130 -132 -132 -133 NA ...
##  $ y    : num [1:15871] 55.9 56.7 57 58.4 NA ...
##  $ range: num [1:4] -180 190.3 -85.4 83.6
##  $ names: chr [1:2284] "Canada" "South Africa" "Denmark" "Great Lakes:Superior, Huron, Michigan" ...
##  - attr(*, "class")= chr "map"
world.map<-as.data.frame(world.map[c("x","y")])
world.map<-ggplot(world.map,aes(x,y))
world.map<-world.map+geom_path()
# http://cran.r-project.org/web/packages/ggplot2/ggplot2.pdf#page=79

Map

plot(world.map)

plot of chunk unnamed-chunk-7