November 28, 2020

Synopsis

I maKe an interactive leaflet map, of the magnitude and depth of quakes, center at Madrid, Spain. Source: < https://www.ign.es/web/ign/portal/sis-catalogo-terremotos>

knitr::opts_chunk$set(echo = TRUE)

Load the data

getwd()
## [1] "C:/Users/pruebas/Documents/Leaflet_map"
setwd("C:/Users/pruebas/Documents/Leaflet_map")
quakes <- read.csv2("catalogoComunSV_1606610811979.csv")
head(quakes)
##         Evento        Fecha         Hora      Latitud     Longitud Prof...Km.
## 1  es2020aaaoe   01/01/2020     00:16:29      28.1426     -16.6635          9
## 2  es2020aalxb   01/01/2020     06:00:14      28.0513     -16.2104          4
## 3  es2020aasdq   01/01/2020     09:09:46      36.9558      -2.3569          1
## 4  es2020aawsw   01/01/2020     11:28:44      28.0290     -15.9617         35
## 5  es2020aayib   01/01/2020     12:16:45      42.9123      -3.0648         NA
## 6  es2020abada   01/01/2020     13:11:30      36.4553      -7.4596         33
##         Inten.         Mag. Tipo.Mag.             Localización
## 1                       1.1         4 SW VILAFLOR DE CHASNA.ITF
## 2                       1.2         4       ATLÃ\201NTICO-CANARIAS
## 3           IV          3.7         5             NE PECHINA.AL
## 4                       1.5         4       ATLÃ\201NTICO-CANARIAS
## 5                       1.2         4           SW BERBERANA.BU
## 6                       1.9         4           GOLFO DE CÃ\201DIZ

Cleaning data

library(leaflet)
library(leaflet.providers)

## I am gonna change the column names

names(quakes) <- c("Event", "Date", "Time", "Latitude", "Length", "Depth", " Int.Max", "Magnitude", "Mag.type", "Location")

quakes$Lat <- as.numeric(quakes$Latitude)
quakes$Len <- as.numeric(quakes$Length)
quakes$Mag <- as.numeric(quakes$Magnitude)

quakes <- quakes %>% na.omit()

perimeter <- quakes[chull(quakes$Len, quakes$Lat), ]
popup <- paste ("<n>", quakes$Location,"</n><br>",
               " Mag: ", quakes$Mag.type,"<br>",
               "Depth: " , quakes$Depth, "<br>",
"<b><a href='https://www.ign.es/web/ign/portal/sis-catalogo-terremotos'>Catalogue of quarkes of IGN </a></b>"
                      )

I use leaflet package in R to make the interactive map.

map <- quakes %>% leaflet() %>%
  setView(lng = -3.658592, lat = 40.416948, zoom = 4) %>%
  setMaxBounds(lng1 = -19.482422, lat1 = 25.191689, lng2 = 20.156250, lat2 = 45.480676) %>%
  # Base groups
  addTiles(group = "OpenStreetMap") %>%
  addProviderTiles(providers$Esri.WorldTerrain, group = "Esri") %>%
  addProviderTiles(providers$Stamen.TonerLite, group = "Toner Lite")%>%   addMarkers(lng = quakes$Len, lat = quakes$Lat, popup = popup, clusterOptions = markerClusterOptions() ) %>%
  # Overlay groups
  addPolygons(data =perimeter, lng = ~Len, lat = ~Lat, fill = F, weight = 4.5, color = "magenta", group = "Sismic zone") %>%
  addCircles(~Len, ~Lat,~10 ^ Mag/5, stroke = F, color = "yellow", group = "Magnitude", fillOpacity = 0.6, weight = 30) %>%
  addCircles(~Len, ~Lat, ~30*Depth, stroke = F, color = "red", group = "Depth", weight = 30) %>%
  # Layers control
  addLayersControl(
    baseGroups = c("OpenStreetMap", "Esri", "Toner Lite"),
    overlayGroups = c("Sismic zone", "Magnitud", "Depth"),
    options = layersControlOptions(collapsed = FALSE)
  )

map