This package has been developed as part of the capstone module for Coursera’s Mastering Software Development in R Specialization. This package allows you to load earthquake data from the US National Centers for Environmental Information. These data contains information on destructive earthquakes from 2150 B.C. to the present that meet at least one of the following criteria:
You can install the released version of the NOAA earthquake package by:
library(devtools)
#> Loading required package: usethis
install_github("csgbloom/NOAAearthquake")
#> Downloading GitHub repo csgbloom/NOAAearthquake@HEAD
#>
#> checking for file ‘/tmp/RtmpZSqsvw/remotes344176f32fa0/csgbloom-NOAAearthquake-b0e910d/DESCRIPTION’ ... ✓ checking for file ‘/tmp/RtmpZSqsvw/remotes344176f32fa0/csgbloom-NOAAearthquake-b0e910d/DESCRIPTION’
#> ─ preparing ‘NOAAearthquake’:
#> checking DESCRIPTION meta-information ... ✓ checking DESCRIPTION meta-information
#> ─ checking for LF line-endings in source and make files and shell scripts
#> ─ checking for empty or unneeded directories
#> ─ building ‘NOAAearthquake_0.1.0.tar.gz’
#>
#>
#> Installing package into '/home/murray/R/x86_64-pc-linux-gnu-library/3.6'
#> (as 'lib' is unspecified)
library(NOAAearthquake)
The function eq_clean_data():
Date
field from the original Year
, Mo
and
Dy
fields, adding 01-01 where no month or day in original
datadf1 <- eq_clean_data(system.file("extdata", "earthquakes.tsv", package = "NOAAearthquake"))
head(df1$Date)
#> [1] "-2150-01-01" "-2000-01-01" "-2000-01-01" "-1610-01-01" "-1566-01-01"
#> [6] "-1450-01-01"
The function eq_location_clean():
Location Name
field into
Location Name
and Country
df2 <- eq_location_clean(df1)
head(df2$Country)
#> [1] "Jordan" "Syria" "Turkmenistan" "Greece" "Israel"
#> [6] "Italy"
The function geom_timeline():
library(tidyverse)
#> ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
#> ✓ ggplot2 3.3.3 ✓ purrr 0.3.4
#> ✓ tibble 3.1.0 ✓ dplyr 1.0.5
#> ✓ tidyr 1.1.3 ✓ stringr 1.4.0
#> ✓ readr 1.4.0 ✓ forcats 0.5.1
#> ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
#> x dplyr::filter() masks stats::filter()
#> x dplyr::lag() masks stats::lag()
df2 %>%
dplyr::filter(Country %in% c("Mexico", "Turkey"), lubridate::year(Date) > 2000) %>%
ggplot2::ggplot(aes(x = Date, y = Country, color = `Total Deaths`, size = Mag)) +
geom_timeline() +
ggplot2::labs(size = "Richter scale value", col = "# Deaths")
The function theme_timeline():
df2 %>%
dplyr::filter(Country %in% c("Mexico", "Turkey"), lubridate::year(Date) > 2000) %>%
ggplot2::ggplot(aes(x = Date, y = Country, color = `Total Deaths`, size = Mag)) +
geom_timeline() +
theme_timeline() +
ggplot2::labs(size = "Richter scale value", col = "# Deaths")
The function geom_timeline_label():
Location Name
labels to the earthquakes of the highest
magnitude for that year rangen_max
df2 %>%
dplyr::filter(Country %in% c("Mexico", "Turkey"), lubridate::year(Date) > 2000) %>%
ggplot2::ggplot(aes(x = Date, y = Country, color = `Total Deaths`, size = Mag)) +
geom_timeline() +
geom_timeline_label(aes(label = `Location Name`), n_max = 3) +
theme_timeline() +
ggplot2::labs(size = "Richter scale value", col = "# Deaths")
#> Warning: `group_by_()` was deprecated in dplyr 0.7.0.
#> Please use `group_by()` instead.
#> See vignette('programming') for more help
The function eq_map():
df2 %>%
dplyr::filter(Country == "Turkey", lubridate::year(Date) >= 2010) %>%
eq_map(annot_col = "Date")
The function eq_create_label():
Location
, Magintude
and Total
Deaths
fieldsdf2 %>%
dplyr::filter(Country == "Turkey", lubridate::year(Date) >= 2010) %>%
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.