library('NOAAEQ')
library(ggplot2)
library(leaflet)

__NOAA EQ_ is package used to ultimately visualize data related to historic earthquakes. The data set comes from the National Oceanic and Atmospheric Administration (NOAA) set of historical data.

Reading and Cleaning Data

One of the primary components to any analysis in R is importing data into an R object. Due to the standard naming convenctions of the file formats in NOAA data and the static nature of the fields, the steps to import data have been built into custom fuction: eq_clean_data This function will not only read in the data but also clean it for the repeatable analysis and visualization built into the package.

eq_clean_data() provides multiple ways to read in the data due to the underlying use of the reader::read_delim(). The default is set to the standard .txt file layout of tab delimited; however, any delimted nature can be used when providing a file argument. Alternatively, one can proivde a data.frame directly to be cleaned if the data is already read into R. An example data set from NOAA has been included in the package and can be accessed as follows:

EQdata<-eq_clean_data(file=system.file("extdata", "signif.txt", package = "NOAAEQ"))

print(head(EQdata))

eq_location_clean() is used within eq_clean_data() to split the Country from the Location data. You should never need to use this function directly.

EQdata<-EQdata<-eq_clean_data(file=system.file("extdata", "signif.txt", package = "NOAAEQ"))

#Compare the split location to original
print(head(EQdata[,c("I_D","COUNTRY","LOCATION_NAME")]))

Visualizing Over Time

geom_timeline() and geom_timeline_label() are shorthand ways of adding a an annotated timeline to the strong graphical arsenal of ggplot2. The calls take date filter arguments xmindate and xmaxdate that will limit the amount of data that gets plotted. At this time, you need to pass consistent x, y, xmindate, and xmaxdate to geom_timeline() and geom_timeline_label() so the timeilne makes sense.

Per standard ggplot2 functionality, many arguments can be passed through aes() to control the points and line colors, transparency, and so on.

p<- EQplotCountry<-ggplot2::ggplot(dplyr::filter(EQdata,COUNTRY %in% c("USA","CHINA")),
                                   mapping=ggplot2::aes(x=DATE,y=COUNTRY))+
                                  geom_timeline(xmindate=lubridate::make_date(2015,1,1))+
                                  geom_timeline_label(ggplot2::aes(orderdata=EQ_PRIMARY,
                                        label=LOCATION_NAME),
                                        xmindate=lubridate::make_date(2015,1,1),n_max=1)
print(p)

Visualizing in Space

NOAAEQ leverages leaflet package and leverages the longitude and latitude fields to make interactive geographic map of the EQ data. The hovers are controlled with the annot_col argument. Using the eq_create_label() function, elaborate hover/pop-up informatoion can be passed into annot_col by simply stating the columns desired.

EQdata$hover_labels<-eq_create_label(EQdata)

eq_map(EQdata,annot_col = "hover_labels")


JJNewkirk/NOAAEQ documentation built on May 27, 2019, 1:12 p.m.