knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Introduction

The goal of earthquakes is to complete the MSDR Capstone project on Coursera.

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.

The overall goal of the capstone project is to integrate the skills you have developed over the courses in this Specialization and to build a software package that can be used to work with the NOAA Significant Earthquakes dataset. 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 or of R. Your job is to provide the tools for processing and visualizing the data so that others may extract some use out of the information embedded within.

The ultimate goal of the capstone is to build an R package that will contain features and will satisfy a number of requirements that will be laid out in the subsequent Modules.

Install % load package 'earthquakes'

library(devtools)
install_github("raggichr/earthquakes")
library(earthquakes)

How to read the data into the R environment?

Run the following code:

filename <- system.file("extdata", "signif.txt", package = "earthquakes")
library(readr)
eq_data_raw <- readr::read_delim(file = filename, delim = "\t")
eq_data <- eq_clean_data(eq_raw = eq_data_raw)
head(eq_data_raw$LOCATION_NAME)
head(eq_data$LOCATION_NAME)

How to make a time line plot of earthquakes for different countries?

See the R code below, for example:

library(dplyr)
library(ggplot2)
library(ggthemes)
eq_data %>%
    dplyr::filter(DATE >= "1995-01-01" & 
                      DATE <= "2018-01-01" &
                      COUNTRY %in% c("USA","ITALY","MEXICO")) %>%
    ggplot(aes(x = DATE,
               y = COUNTRY,
               colour = DEATHS,
               size = EQ_PRIMARY)) +
    geom_timeline() +
    geom_timeline_label(aes(x = DATE, 
                            y = COUNTRY, 
                            tags = LOCATION_NAME, 
                            number = 3, 
                            max_aes = EQ_PRIMARY)) +
    theme_tufte() +
    theme(legend.position = "right")

How to map the earthquakes?

Each earthquake should be shown with a circle, and the radius of the circle should be proportional to the earthquake's magnitude (EQ_PRIMARY). Your code, assuming you have the earthquake data saved in your working directory as "earthquakes.tsv.gz", should be able to be used in the following way:

library(dplyr)
library(lubridate)
library(leaflet)
eq_data %>%
    filter(COUNTRY %in% "ITALY" &
               lubridate::year(DATE) >= 2000) -> eq_data_sample

eq_data_sample %>%
    eq_clean_data() %>%
    filter(COUNTRY %in% "ITALY" & lubridate::year(DATE) >= 2000) %>%
    eq_map(annot_col = "DATE")

eq_data_sample %>%
    eq_clean_data() %>%
    filter(COUNTRY %in% "ITALY" & lubridate::year(DATE) >= 2000) %>%
    mutate(popup_text = eq_create_label(.)) %>%
    eq_map(annot_col = "popup_text")


raggichr/earthquakes documentation built on June 25, 2020, 5:45 p.m.