knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
National Oceanographic and Atmospheric Administration (NOAA) collects significant earthquakes around the world and make a dataset that contains information about 5,933 earthquakes over an approximately 4,000 year time span. This dataset has a substantial amount of information embedded in it that may not be immediately accessible to people without knowledge of the intimate details of the dataset.
The overall goal of the R package is to work with this dataset and provide the tools for processing and visualizing the data so that others may extract some use out of the information embedded within.
library(devtools) devtools::install_github('willojs/earthquakesNOAA', build_vignettes = TRUE) library(earthquakesNOAA)
Download the data from the NOAA website, saved it to your working directory and transform it to a data frame using the read_delim
function:
Clean data
filename <- system.file("extdata","earthquake.txt", package="earthquakesNOAA") library(readr) data <- readr::read_delim(filename, delim = "\t")
Before using the visualization tools, the data must be cleaned with the functions eq_clean_data
and eq_location_clean
.
clean_data <- eq_clean_data(data) clean_data <- eq_location_clean(clean_data)
To map the earthquakes epicenters in Mexico since 2000 and providing their dates in annotation use the eq_map
function:
clean_data %>% dplyr::filter(COUNTRY == "MEXICO" & lubridate::year(DATE) >= 2000) %>% eq_map(annot_col = "DATE")
To show annotations, use the eq_create_label
function before the eq_map
function:
clean_data %>% dplyr::filter(COUNTRY == "MEXICO" & lubridate::year(DATE) >= 2000) %>% dplyr::mutate(popup_text = eq_create_label(.)) %>% eq_map(annot_col = "popup_text")
To visualize the times, the magnitudes and the number of deaths associated to earthquakes within certain countries, use the geom_timeline
geom with the ggplot
function:
data %>% dplyr::filter(COUNTRY == c("MEXICO","USA") & lubridate::year(DATE) >= 2010) %>% ggplot(aes(x=DATE,y=COUNTRY,color=TOTAL_DEATHS,size=EQ_PRIMARY)) + geom_timeline(alpha=.5) + theme(legend.position="bottom", legend.box="horizontal", plot.title=element_text(hjust=0.5)) + ggtitle("Earthquakes Visualization Tool") + labs(size = "Richter scale value", color = "# deaths")
Use the geom_timelinelabel
geom for adding annotations to the earthquake data and an option to subset the n_max largest earthquakes by magnitude:
```r data %>% dplyr::filter(COUNTRY == c("MEXICO","USA") & lubridate::year(DATE) >= 2010) %>% ggplot(aes(x=DATE,y=COUNTRY,color=TOTAL_DEATHS,size=EQ_PRIMARY)) + geom_timeline(alpha=.5) + geom_timelinelabel(aes(label=LOCATION_NAME),n_max=3) + theme(legend.position="bottom", legend.box="horizontal", plot.title=element_text(hjust=0.5)) + ggtitle("Earthquakes Visualization Tool") + labs(size = "Richter scale value", color = "# deaths")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.