Want to see the code? Click on the black boxes on the right to show/hide the code.

Here’s a classic map using data from the Humanitarian Data Exchange (HDX). Recent 2.5+ magnitude earthquakes (from USGS data) displayed alongside tectonic plates from the University of Texas Institute for Geophysics (UTIG).

# Let's load the sf and mapview libraries to process and view geospatial data
library(sf)
library(dplyr)
library(mapview)
library(leafpop)
#library(raster)
#library(terra)

# The PLATES dataset consists of three shapefiles, one for the each type of boundary
# ridge, trench and transforms. Let's readt these in, and then use dplyrs bind_rows function
# to merge them into a single spatial data frame.
ridge <- st_read('./data/08/ridge.shp', quiet = TRUE)
trench <- st_read('./data/08/trench.shp', quiet = TRUE)
transform <- st_read('./data/08/transform.shp', quiet = TRUE)

plates <- bind_rows(trench, ridge, transform)

# Next we'll read in the past weeks' 2.5+ magnitude quakes from USGS 
quakes <- st_read('./data/08/2.5_week.geojson', quiet = TRUE)

# And finally, display it on a map.
mapviewOptions(basemaps = c("Esri.WorldShadedRelief"),
               layers.control.pos = "topright",
               leafletWidth = "100%",
               legend = FALSE,
               fgb = FALSE
               )

mapview(quakes, label="mag", cex = quakes$mag*2.5, col.regions="red", layer.name = "Earthquakes", popup = popupTable(quakes, zcol=c("title","place","mag")) ) + mapview(plates, layer.name = "Tectonic plates") 

Credits

Tectonic plates: University of Texas Institute for Geophysics (UTIG) https://data.humdata.org/dataset/tectonic-plate, Creative Commons Attribution International license https://creativecommons.org/licenses/by/4.0/legalcode

Earthquakes: USGS https://data.humdata.org/dataset/usgs-magnitude-2-5-earthquakes, Creative Commons Attribution International license https://creativecommons.org/licenses/by/4.0/legalcode