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

Introduction

This package handles the dataset about earthquakes provided by the U.S. National Oceanographic and Atmospheric Administration (NOAA). It is made for educational purpose, as the final assignment of the Coursera MSDR Capstone project.

Install the package

library(ggplot2)
library(dplyr)
library(tidyr)
library(lubridate)
# library(devtools)
# install_github("BFavetto/EarthquakeAnalysis")
library(EarthquakeAnalysis)

Load and clean the NOAA dataset

The data is inculded in the package and can be easily loaded.

# to load the data from the package
data("NOAAdata")

dataclean1 <- eq_clean_data(NOAAdata)
# View(dataclean1)
dataclean2 <- eq_location_clean(dataclean1)
# View(dataclean2)

head(dataclean2)

Plot a time line for earthquakes

A time line is plotted with circles to date the earthquakes. The radii of the circles are proportional to the magnitude of the earthquakes.

dataclean2 %>% filter((Year > 2010) &  (Country =="INDIA")) %>%
ggplot(  aes(x = Date,
           y = Country,
           color = Deaths,
           size = Mag)) + geom_timeline(alpha = 0.2)

Plot a time line with labels

If there are several countries, a time line is plotted for each.

dataclean2 %>% filter(Country %in% c("MEXICO", "IRAN") &
                      Date %within% interval(ymd(20000103),
                                                    ymd(20180104))) %>%
               mutate(Country = factor(Country, levels = unique(Country))) %>%
               ggplot() +
                    geom_timeline_label(aes(x = Date,
                                            y = Country,
                                            label = Location,
                                            magnitude = Mag,
                                            colour = Deaths,
                                            n_max = 7), alpha = 0.5) +
                               scale_colour_continuous(name = "Nb. of deaths") +
                               theme(legend.position = "bottom") +
                               ylab("")

Plot a map with locations and dates for earthquakes

dataclean2 %>%
  filter(Country == "MEXICO" & year(Date) >= 2000) %>%
  eq_map(annot_col = "Date")

A version with more information in the popup is available.

dataclean2 %>%
 filter(Country %in% c("HONDURAS", "MEXICO") & year(Date) >= 2000) %>%
 mutate(popup_text = eq_create_label(.)) %>%
 eq_map( annot_col = "popup_text")


BFavetto/EarthquakeAnalysis documentation built on Dec. 17, 2021, 9:50 a.m.