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.
There are six exported functions available to users:
eq_clean_data()
geom_timeline()
geom_timeline_label()
theme_timeline()
eq_create_label()
eq_map()
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)
Three functions use ggplot2
to plot an earthquake timeline:
geom_timeline()
requires cleaned data. You should provide dates to the required aesthetics x
, and countries to the optional aesthetics y
. , You can set size
and color
according to your needs. geom_timeline_label()
function requires additional label
aesthetic for labeling. theme_timeline()
is available as well. 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")
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.