knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(CapstoneOne) library(magrittr) library(dplyr) library(readr) library(tidyr) library(ggplot2) library(stringr) library(grid) library(scales) library(lubridate) library(leaflet)
This capstone project will be centered around a dataset 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. 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. This package provides the tools for processing and visualizing the data so that others may extract some use out of the information embedded within.
The NOAA earthquake data is held online on the NOAA website. See https://www.ngdc.noaa.gov/hazel/view/hazards/earthquake/event-data for more details.
This package enables users to plot earthquake information as ggplot charts and as leaflet maps. To use the package, download a NOAA file (note that a version is included in the package) and run the eq_location_clean function to standardise country names:
basePath <- system.file('extData', package='CapstoneOne') inputFileLocation <- paste0(basePath,"/earthquakes-2021-06-25_15-27-06_+0100.tsv") rawData <- read_noaa_file(inputFileLocation) eqData <- eq_location_clean(rawData)
You can plot a timeline for a set of countries using ggplot. Note that we have implemented a new ggplot theme to aid the visuals:
ggplot(eqData %>% filter(Country %in% c("China", "Greece") & year(Date) > 1990), aes(x=Date, y=Country, label=Location, n_max=5, colour=Deaths, size=Mag), alpha=0.1) + geom_timeline() + scale_shape_identity() + theme_quake() + labs(size="Richter Scale", colour="Casualties")
Labels can also be added:
ggplot(eqData %>% filter(Country %in% c("China", "Greece") & year(Date) > 1990), aes(x=Date, y=Country, label=Location, n_max=5, colour=Deaths, size=Mag), alpha=0.1) + geom_timeline() + geom_timeline_label() + scale_shape_identity() + theme_quake() + labs(size="Richter Scale", colour="Casualties")
You can plot the earthquakes on a map using leaflet:
eq_map(eqData %>% filter(Country == "China" & year(Date) > 2000), annot_col = "Location")
Custom labels for the leaflet locations are also available:
eq_map_label(eqData %>% filter(Country == "China" & year(Date) > 2000))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.