knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(knitr)
library(dplyr)
library(ggplot2)
library(NOAA)

This Package includes functions used to read in and map earthquake data from National Oceanic and Atmospheric Administration (NOAA), which is a American scientific agency within the United States Department of Commerce that focuses on the conditions of the oceans, major waterways, and the atmosphere.

Functions

eq_get_data This function takes a country name in all capitals, a start date as a string in 'YYYY-MM-DD' format, and optionally an end date in the same format, read in the earthquake data, cleans it, and turns a filtered cleaned dataframe.

eq_clean_data This function takes a dataframe and drops date related NAs, converts data types to appropriate type, removes pre-BC dates due to low information, fixes date parts that do not fit conventionall format, and returns a cleaned dataframe.

eq_location_clean This funtion cleans the LOCATION_NAME column by stripping out the country name (including the colon) and converts names to title case (as opposed to all caps).

geom_timeline This function uses ggplot to creat a custom geom to visualize a timeline of earthquakes.

geom_timeline_label This function creates a new geom that can build on geom_timeline and add labels to the top n biggest earthqakes by magnitude.

eq_map This function plots earthquakes and avaialble information about said earthquakes on an interactive map that will allow the used to click on an earthquake to see the relevant details.

eq_create_label This function add date, location, magnitude, and total deaths, in an annotation on an interactive map.

Example of eq_get_data:

filename <- system.file('extdata', 'earthquakes.tsv.gz', package = 'NOAA')
data<-eq_get_data(filename, country = c('MEXICO','USA'), start_date = '2006-01-01', end_date = '2009-01-01')
head(data)

Example of geom_timeline and geom_timeline_label:

data %>% 
  ggplot2::ggplot() +
  geom_timeline(
    aes(
      x = DATE,
      y = COUNTRY,
      fill = TOTAL_DEATHS,
      size = EQ_PRIMARY)
  ) +
  geom_timeline_label(
    aes(
      x = DATE,
      y = COUNTRY,
      magnitude = EQ_PRIMARY,
      label = LOCATION_NAME,
      n_max=3) # number of lables to show

  )

Example of eq_map:

data %>%
     dplyr::mutate(popup_text = eq_create_label(.)) %>%
     eq_map(annot_col = "popup_text")


ctaber/NOAA documentation built on Nov. 4, 2019, 9:19 a.m.