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

This package was designed to provide visualising methodes for earthquake data. These data were provided by the U.S. National Oceanographic and Atmospheric Administration (NOAA) Significant Earthquake Database. The data set contains information on 5,933 earthquakes that occurred in a 4,000-year period. The data set is in the directory date from the package (see the file signif.txt).

Installation

This package depends on the following packages: dplyr, ggplot2,leaflet,stringr,lubridate,tidyr, grid,purrr,rlang, readr,stringr, sp, rworldmap. Make sure you have the above packages installed.

The NOOA package can be installed from github using the commands:

library(devtools)
install_github("constantin345/NOOA")
library(NOOA)

Description

The package provides the user the next functions:

load_data Load in a dataframe the file signif.txt.

library(NOOA)
df <- load_data()

fix_na_latitude - solves the cases (from dataframe) with LATITUDE is NA and LONGITUDE is not NA.

dfnew <- load_data()
dfnew <- dplyr::mutate(dfnew, LATITUDE=as.numeric(LATITUDE))
dfnew <- dplyr::mutate(dfnew, LONGITUDE=as.numeric(LONGITUDE))
dfnew <- dplyr::mutate(dfnew, EQ_PRIMARY=as.numeric(EQ_PRIMARY))
dfnew <- dplyr::mutate(dfnew, DEATHS=as.numeric(DEATHS))
dfnew <- fix_na_latitude(dfnew)

fix_na_longitude - solves the cases (from dataframe) with LATITUDE is not NA and LONGITUDE is NA.

dfnew <- load_data()
dfnew <- dplyr::mutate(dfnew, LATITUDE=as.numeric(LATITUDE))
dfnew <- dplyr::mutate(dfnew, LONGITUDE=as.numeric(LONGITUDE))
dfnew <- dplyr::mutate(dfnew, EQ_PRIMARY=as.numeric(EQ_PRIMARY))
dfnew <- dplyr::mutate(dfnew, DEATHS=as.numeric(DEATHS))
dfnew <- fix_na_longitude(dfnew)

fix_na_lon_na_lat - solves the cases (from dataframe) with LATITUDE is NA and LONGITUDE is NA.

dfnew <- load_data()
dfnew <- dplyr::mutate(dfnew, LATITUDE=as.numeric(LATITUDE))
dfnew <- dplyr::mutate(dfnew, LONGITUDE=as.numeric(LONGITUDE))
dfnew <- dplyr::mutate(dfnew, EQ_PRIMARY=as.numeric(EQ_PRIMARY))
dfnew <- dplyr::mutate(dfnew, DEATHS=as.numeric(DEATHS))
dfnew <- fix_na_lon_na_lat(dfnew)

eq_clean_data - A new dateframe is created (a cleaned dataframe) from a raw dataframe by uniting the year, month, day in a single Date column (named DataEQ) and converting some columns (LATITUDE, LONGITUDE, EQ_PRIMARY and DEATHS) to numeric.Also I realized data imputation calling fix_na... functions in the body of this function.

df <- load_data()
df <- eq_clean_data(df)

eq_location_clean - Cleans the LOCATION_NAME column by stripping out the country name (including the colon) and converts names to title case (as opposed to all caps).

dfnew <- load_data()
dff <- eq_location_clean(dfnew)

fix_countries - Checks that the country in which the location (given by the columns LATITUDE and LONGITUDE) is the same with the value from COUNTRY column. If there are differences, the value from the COUNTRY column is updated.

dfnew <- load_data()
dfnew <- dplyr::mutate(dfnew, LATITUDE=as.numeric(LATITUDE))
dfnew <- dplyr::mutate(dfnew, LONGITUDE=as.numeric(LONGITUDE))
dfnew <- dplyr::mutate(dfnew, EQ_PRIMARY=as.numeric(EQ_PRIMARY))
dfnew <- dplyr::mutate(dfnew, DEATHS=as.numeric(DEATHS))
dfnew <- fix_na_latitude(dfnew)
dfnew <- fix_na_longitude(dfnew)
dfnew <- fix_na_lon_na_lat(dfnew)
dfnew <- dplyr::mutate(dfnew, DataEQ=convert_data(YEAR, MONTH, DAY))
test <- fix_countries(dfnew)

remove_countries - Removes from column LOCATION_NAME (a NOAA dataframe) the stringswhich representing a name of country.

dfnew <- load_data()
dff <- remove_countries(dfnew)

convert_data - A date vector is created by uniting the year, month, day and converting it to the Date class

Year <- c(-11, -100, -200, -300, 2000, 0)
Month <- c(NA, NA, NA, 9, 8, 1)
Day <- c(8, NA, 7, 29, 20, 12)
convert_data(Year, Month, Day)

geomTimeline - Function to construct a new class for the geom_timeline geom_timeline- A ggplot2 graphical function to plot a timeline of earthquakes from cleaned data. The plot indicates the magnitude of each earthquake and number of deaths. geomTimelineLabel- Function to construct a new class for the geom_timeline geom_timeline_label geom_timeline_label - This geom adds a vertical line to each data point with a text annotation (e.g. the location of the earthquake) attached to each line. and number of deaths.

df <- load_data()
df <- eq_clean_data(df)
df <- eq_location_clean(df)

country <- c("JAPAN")
dfFilter <- filterData(df, COUNTRY=country, minYear=1000, maxYear=1400)

test <- (ggplot2::ggplot()+
            geom_timeline(data=dfFilter,ggplot2::aes(x=DataEQ,
                                            xmin=as.Date("1000-01-01"),
                                            xmax=as.Date("1400-12-31"),
                                            colour=DEATHS,
                                            fill=DEATHS,
                                            size=EQ_PRIMARY,
                                           y=COUNTRY))+
            geom_timeline_label(data=dfFilter, ggplot2::aes(x=DataEQ,
                                                   location=LOCATION_NAME,
                                                   size=EQ_PRIMARY,
                                                   n_max=5,
                                                   y=COUNTRY)))
g <- setupGeom(test)
g

eq_map - The function show on a map eartquakes for a particular country. All earthquakes are represented by circle on the map. A column from the data could be specified by user. This column is annotated. In the example the column is DataEQ.

df <- load_data()
df <- eq_clean_data(df)
df <- dplyr::filter(df, COUNTRY == "MEXICO" & lubridate::year(DataEQ) >= 2000)
g <- eq_map(df, annot_col = "DataEQ")
g <- eq_map(dff, annot_col = "DataEQ") 
g

setupGeom - Create a ggplot theme and add this to an ggplot object. filterData - A cleaned NOOA dataframe is prepared for visualisation. That means that the eartquakes are filtered after a vector of COUNTRY and a period of time. The period of time is given between a minYear and maxYear. ```R df <- load_data() df <- eq_clean_data(df) df <- eq_location_clean(df) country <- c("JAPAN") dfFilter <- filterData(df, COUNTRY=country, minYear=1000, maxYear=1400) test <- (ggplot2::ggplot()+ geom_timeline(data=dfFilter,ggplot2::aes(x=DataEQ, xmin=as.Date("1000-01-01"), xmax=as.Date("1400-12-31"), colour=DEATHS, fill=DEATHS, size=EQ_PRIMARY, y=COUNTRY))+ geom_timeline_label(data=dfFilter, ggplot2::aes(x=DataEQ, location=LOCATION_NAME, size=EQ_PRIMARY, n_max=5, y=COUNTRY)))

a <- setupGeom(test)

 `create_map` - The function draw the epicenters eartquakes
(LATITUDE/LONGITUDE) from a filtered NOAA dataframe.
Each point is annotates with an pop up window containing
annotation data stored in a column of the data frame. This function is called by eq_map.
```R
df <- load_data()
df <- eq_clean_data(df)
df <- eq_location_clean(df)

dff <- dplyr::filter(df, COUNTRY=="CHINA" & YEAR>=2010)
magnitude <- ifelse(is.na(dff$EQ_PRIMARY),4,dff$EQ_PRIMARY)

content <- paste("<b>Location:</b>", df$LOCATION_NAME,"<br/>",
                  "<b>Magnitude:</b>", df$EQ_PRIMARY,"<br/>",
                  "<b>Total deaths:</b>", df$TOTAL_DEATHS)

a <- create_map(dff, content)

coords2country - Finds the country where the lation is located by LATITUDE and LONGITUDE. This function is used by the fix_countries function. R country <- coords2country(33.40,73.30)



constantin345/NOOA documentation built on May 16, 2019, 7:09 p.m.