This is an R package to analyse the data "NOAA Significant Earthquake Database" in Capstone Sofware Development in R.

Capstone's functions:

Examples

Download the data signif.txt from the NOAA website, put it to your working directory and transform it to a data frame using the read_delim function:

library(readr)
data <- readr::read_delim("signif.txt", delim = "\t")

Then clean the data 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 Canada since 2000 and get their dates in annotation use the eq_map function.

clean_data %>%
  dplyr::filter(COUNTRY == "CANADA" & lubridate::year(DATE) >= 2000) %>%
  eq_map(annot_col = "DATE")

To get annotation the Location, Total deaths, and Magnitude of the earthquakes, use the eq_create_label function before the eq_map function.

clean_data %>%
  dplyr::filter(COUNTRY == "CANADA" & lubridate::year(DATE) >= 2000) %>%
  dplyr::mutate(popup_text = eq_create_label(.)) %>%
  eq_map(annot_col = "popup_text")

To visualize times, magnitudes of earthquakes in Canada and USA, we use the geom_timeline geom.

data %>%
  dplyr::filter(COUNTRY == c("CANADA","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") 

To add annotations to the earthquake data, we use geom_timelinelabel geom

data %>%
  dplyr::filter(COUNTRY == c("CANADA","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") 


vnmath/SoftwareDevinR documentation built on July 6, 2020, 9:36 a.m.