knitr::opts_chunk$set(collapse = TRUE, comment = "#>", fig.width = 7, fig.height = 7, fig.align = "center")

Earthquake Tools Package - eqtools

The eqtools package makes it easy for users to explore the U.S. National Oceanographic and Atmospheric Administration (NOAA) dataset on significant earthquakes around the world. This dataset contains information about 5,933 earthquakes over an approximately 4,000 year time span.

Downloading dataset

The datset is available from the NOAA Website The entire dataset can be download by clicking on the link: "Download entire significant earthquake data file in tab-delimited format."

What Eqtools includes

Data: NOAA significant earthquake data

     library(readr)
     eqdata <- read_delim(  system.file("extdata",
                          "signif-july-2017.txt.gz",
               package = "eqtools"),delim = "\t")
    dim(eqdata)

Cleaning tools

eq_clean_data convert LATITUDE and LONGITUDE to numeric

    library(eqtools)
    str(eqdata$LATITUDE)
    eq_data_clean <- eq_clean_data(eqdata)
    str(eq_data_clean$LATITUDE)

eq_clean_location removes country from LOCATION_NAME and converts it to title case

    eqdata$LOCATION_NAME[1]
    eq_data_ready <- eq_clean_location(eq_data_clean)
    eq_data_ready$LOCATION_NAME[1]

Plotting Tools

geom_timeline() creates a timeline plot of eathquakes by year

    library(dplyr)
    library(ggplot2)
    library(grid)
    minDate <- as.Date("2000-1-1","%Y-%m-%d")     
    maxDate <- as.Date("2015-12-31","%Y-%m-%d")   
    eq_us_mex_data <- mutate(eq_data_ready) %>%
          filter( DATE >= minDate,DATE <= maxDate, COUNTRY %in% c("USA","MEXICO")) %>%
      mutate(EQ_PRIMARY = as.numeric(EQ_PRIMARY))
     ggplot(eq_us_mex_data,aes(x = DATE, y = 1,
         xmin = minDate,xmax = maxDate,
         )) +
  geom_timeline(aes(size = EQ_PRIMARY))

geom_timeline_label() adds labels to the geom_timeline plot

    #library(ggplot2)
     ggplot(eq_us_mex_data,aes(x = DATE, y = 1,
         xmin = minDate,xmax = maxDate,
         )) +
  geom_timeline(aes(size = EQ_PRIMARY)) +
  geom_timeline_label(aes(label = LOCATION_NAME,size = EQ_PRIMARY,n_max = 5))

If y is set to a data column the timelines are split up. xlim and ylim can be added to adjust for labels.

    #library(ggplot2)
     ggplot(eq_us_mex_data,aes(x = DATE, y = COUNTRY,
         xmin = minDate,xmax = maxDate,
         )) +
  geom_timeline(aes(size = EQ_PRIMARY)) +
  geom_timeline_label(aes(label = LOCATION_NAME,size = EQ_PRIMARY,n_max = 5)) + 
  xlim(as.Date("1999-1-1","%Y-%m-%d"),as.Date("2017-12-31","%Y-%m-%d")  ) + 
  ylim(c(as.character(unique(eq_us_mex_data$COUNTRY)),""))

Mapping Tools

eq_map creates a leaflet map

      library(leaflet)

      #eq_map(eq_us_mex_data,annot_col = "DATE")

eq_create_label() formats information to be used in a web popup

  popup_labels <- eq_create_label(eq_us_mex_data) 
  paste(popup_labels[1],"\n")

"He who gives up [code] safety for [code] speed deserves neither." (via)



tcoopermont/eqtools documentation built on May 30, 2019, 7:21 a.m.