knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "README-"
)
require(dplyr)
require(htmlwidgets)
require(webshot)
require(rEarthQuakes)

rEarthQuakes

Build Status

Description

The goal of rEarthQuakes is to make it easy visualize the data from NOAA's Significant Earthquake Database. This database obtained from the U.S. National Oceanographic and Atmospheric Administration (NOAA) on significant earthquakes around the world. This dataset contains information about 5,933 earthquakes over an approximately 4,000 year time span.

NOAA Significant Earthquake Database

Examples

We start by download the NOAA Significant Earthquake Database.

data <- readr::read_delim("https://www.ngdc.noaa.gov/nndc/struts/results?type_0=Exact&query_0=$ID&t=101650&s=13&d=189&dfn=signif.txt", delim = "\t")

This creates a ggplot2 object with earthquake timelines and labels grouped by country, colored by number of casualties and sized by magnitude.

data %>%
        eq_clean_data() %>%
        filter(COUNTRY %in% c("USA", "CHINA"), YEAR > 2005) %>%
        ggplot(aes(x = DATE,
                   y = COUNTRY,
                   color = as.numeric(TOTAL_DEATHS),
                   size = as.numeric(EQ_PRIMARY)
                   )) +
        geom_timeline() +
        geom_timeline_label(aes(label = LOCATION_NAME), n_max = 5) +
        theme_timeline() +
        labs(size = "Richter scale value", color = "# deaths") + 
        scale_x_date(limits = c(lubridate::ymd("2005-01-01"), 
                                lubridate::ymd("2018-01-01")))

We can also plot the individual earthquakes on an interactive leaflet map including their location name, magnitude, and number of casualties as annotation.

data %>% 
  eq_clean_data() %>% 
  dplyr::filter(COUNTRY == "MEXICO" & YEAR >= 2000) %>% 
  dplyr::mutate(popup_text = eq_create_label(.)) %>% 
  eq_map(annotation = "popup_text") -> map
map %>% addProviderTiles(providers$OpenStreetMap) -> map
saveWidget(map, "leaflet.html", selfcontained = FALSE)
p <- webshot("leaflet.html", file = "README-Earthquake Map-1.png", cliprect = "viewport")
knitr::include_graphics("README-Earthquake Map-1.png")

Author

Bart Lauwers



blauwers/rEarthQuakes documentation built on May 7, 2019, 2:54 a.m.