- Aim: create and display an interactive map of recent earthquakes around Italy and the surrounding seas
- Data taken from the Italian National Institute of Geophysics and Volcanology
20 October 2017
if(!file.exists('earthquakes.txt')) {
download.file('http://webservices.ingv.it/fdsnws/event/1/query?starttime=2017-10-09T00%3A00%3A00&endtime=2017-10-16T23%3A59%3A59&minmag=2&maxmag=10&mindepth=-10&maxdepth=1000&minlat=-90&maxlat=90&minlon=-180&maxlon=180&minversion=100&orderby=time-asc&format=text&limit=10000', destfile = 'earthquakes.txt', method = "curl")
}
df <- read.csv('earthquakes.txt', header=TRUE, sep="|")
str(df)
## 'data.frame': 63 obs. of 13 variables: ## $ X.EventID : int 17280571 17285641 17286531 17286991 17288681 17289441 17290341 17290871 17292271 17293271 ... ## $ Time : Factor w/ 63 levels "2017-10-09T05:22:18.970000",..: 1 2 3 4 5 6 7 8 9 10 ... ## $ Latitude : num 43 42.7 42.8 38.8 42.8 ... ## $ Longitude : num 13.1 13.1 13.2 15.6 13.2 ... ## $ Depth.Km : num 9.1 10.4 10.3 88.4 10.3 118 11.9 19.5 12.3 10.5 ... ## $ Author : Factor w/ 3 levels "SURVEY-INGV",..: 1 1 1 1 1 1 1 2 1 1 ... ## $ Catalog : logi NA NA NA NA NA NA ... ## $ Contributor : logi NA NA NA NA NA NA ... ## $ ContributorID : logi NA NA NA NA NA NA ... ## $ MagType : Factor w/ 3 levels "Md","ML","Mwp": 2 2 2 2 2 2 2 3 2 2 ... ## $ Magnitude : num 2.5 2 2.4 2.2 2 2.3 2.2 6.2 2 2.2 ... ## $ MagAuthor : Factor w/ 1 level "--": 1 1 1 1 1 1 1 1 1 1 ... ## $ EventLocationName: Factor w/ 45 levels "1 km NE Monte Cavallo (MC)",..: 24 36 32 45 32 41 26 44 28 9 ...
subset(df, !(Longitude>=6.0 & Longitude<=18.5 &
Latitude>=35.0 & Latitude<=48.0),
select=c('Latitude','Longitude','EventLocationName'))
## Latitude Longitude EventLocationName ## 8 -18.4570 -69.72400 Northern Chile [Land: Chile] ## 13 -54.0352 8.26823 Bouvet I. [Sea]
df <- subset(df, Latitude < 0)
library(plotly)
with(df, plot_ly(x = Longitude, y = Latitude,
type="scatter", mode="markers",
color = ~Depth.Km, size=Magnitude) %>%
layout(title = "Earthquakes Around Italy",
xaxis = list(title="Longitude"),
yaxis = list(title = "Latitude")))