library(NoaaCS)
library(dplyr)
library(ggplot2)
library(readr)

This vignette gives a brief overview of the NoasCS R package created for the purpose of visualizing NOAA earthquake data. It processes data from NOAA database and visualizes them using ggplot2 and leaflet packages.

Package functions

There are six exported functions available to users:

Clean data

The function eq_clean_data preprocess the data. It creates a DATE column in Date format, transforms latitude and longitude to numeric format and trims country from LOCATION_NAME.

filename <- system.file("extdata/signif.txt", package = "NoaaCS")
data <- readr::read_tsv(filename)

eq_clean_data(data)

Visualize earthquake timeline

Three functions use ggplot2 to plot an earthquake timeline:

data %>% eq_clean_data() %>%
     filter(COUNTRY %in% c("USA", "CHINA"), YEAR > 2000, DEATHS>0) %>%
     ggplot(aes(x = DATE,
                y = COUNTRY,
                color = DEATHS,
                size = as.numeric(EQ_PRIMARY)
     )) +
     geom_timeline() +
     geom_timeline_label(aes(label = LOCATION_NAME)) +
     theme_timeline() +
     labs(size = "Richter scale value", color = "# deaths")

Visualize earthquakes on map

The package uses leaflet functions to show earthquakes on a map using eq_map() function. Optional annotations can be created using eq_create_label() function. The result is an interactive map where user can click on individual points to get details.

data %>% 
  eq_clean_data() %>% 
  dplyr::filter(COUNTRY == "MEXICO" & lubridate::year(DATE) >= 2000) %>% 
  dplyr::mutate(popup_text = eq_create_label(.)) %>% 
  eq_map(annot_col = "popup_text")


clems/NoaaCS documentation built on May 12, 2019, 1:59 p.m.