README.md

Travis build status AppVeyor build status

Capstone

This package provides several functions in order to work with The NOAA Significant Earthquake Database, which contains historical data of earthquakes around the world, that data cotains several information, like magnitude, number of deaths, localization, date, among others. The purpose of this package is provide functions to work with this data, using all the tools that the previous courses of the Mastering Software Development in R taught us.

Installation

This package is available on GitHub and using the devtools package can be installed:

library(devtools)
install_github("Fr3ddy1/Mastering-Software-Development-in-R-Capstone")
library(capstone)

Examples

eq_clean_data and eq_location_clean functions

The NOAA Earthquakes Data can be downloaded from the NOAA web site or can be use from the extdata folder of this package (earthquakes_data.txt.zip or signif.txt.tsv File).

In order to clean this data two functions were created The eq_clean_data() and eq_location_clean function, the first one generate a datetime column where it unite the day, month, year and hour information of each observation, converts to numeric data a set of columns (LATITUDE, LONGITUDE). On the other hand, the eq_location_clean function to remove the Country from the LOCATION_NAME column.

#set the location of the file
file<-system.file("extdata","earthquakes_data.txt.zip",package="Captsone")
#read the data 
data <- eq_read_data(file)
#clean the data
data_clean <- eq_clean_data(eq_read_data(file))
#work with the LOCATION_NAME column
eq_location_clean(eq_clean_data(eq_read_data(file)))

Geoms

After reading and cleaning the earthquakes Data Set, this information or data can be displayed in a timeline plot, using the geom funcions designed for that task. This functions or geoms were created during the second week of the course.

The first geom created were the geom_timeline which displays a timeline of earthquakes for one or several country and for a specific time range. The second geom were geom_timeline_label which displays the names of each location were the incident ocurred.

In order to obtaind a specific data to apply the geom, the data obtained from the eq_clean_data() and eq_location_clean() functions were filtered. And example to display the earthquakes in Ecuador, Chile y Venezuela from February 1986 to June 2016 is:

#set the name of the file
file<-system.file("extdata","earthquakes_data.txt.zip",package="Capstone")
#generate the timeline
eq_location_clean(eq_clean_data(eq_read_data(file))) %>%
dplyr::filter(DATE >= "1986-02-01" & DATE <="2016-06-01" &
COUNTRY == c("ECUADOR","CHILE", "VENEZUELA"))%>%
ggplot() +
geom_timeline(aes(x = DATE, size = EQ_MAG_ML, colour = DEATHS, fill = DEATHS))

To display the earthquakes in Ecuador, Chile y Venezuela from February 1986 to June 2016 with labels:

#set the name of the file
file<-system.file("extdata","earthquakes_data.txt.zip",package="Capstone")
#generate the timeline
eq_location_clean(eq_clean_data(eq_read_data(file))) %>%
dplyr::filter(DATE >= "1986-02-01" & DATE <="2016-06-01" &
COUNTRY == c("ECUADOR","CHILE", "VENEZUELA"))%>%
ggplot() +
geom_timeline(aes(x = DATE, size = EQ_MAG_ML, colour = DEATHS, fill = DEATHS))

Interactive map

In order to display the earthquakes data in an interactive map the leaflet package can be used. To achieve that goal the LATITUDE and LONGITUDE column were used to locate each event. The eq_map() function is the tool to do this work. This function contains the "name_col" argument which let show information about the earthquake, like location, magnitude, or number of deaths.

To display a map of Earthquakes in Venezuela after 1980:

#set the name of the file
file<-system.file("extdata","earthquakes_data.txt.zip",package="Capstone")
#plot the interactive map
eq_location_clean(eq_clean_data(eq_read_data(file))) %>%
dplyr::filter(COUNTRY == "VENEZUELA" & lubridate::year(DATE) >= 1980) %>%
eq_map(name_col = "DATE")

In order to obtain a label in a specific format the function eq_create_label were created. This function show information about the location, date and number of deaths of each earthquake ploted. To display a map of Earthquakes in Venezuela after 1980, with this label:

#set the name of the file
file<-system.file("extdata","earthquakes_data.txt.zip",package="Capstone")
#plot the interactive map with labels
eq_location_clean(eq_clean_data(eq_read_data(file))) %>%
dplyr::filter(COUNTRY == "MEXICO" & lubridate::year(DATE) >= 1980) %>%
dplyr::mutate(popup_text = eq_create_label(.)) %>%
eq_map(name_col = "popup_text")


Fr3ddy1/Capstone documentation built on May 26, 2019, 7:43 p.m.