knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(Earthquakes4Coursera)
This vignette describes input data and the functions which prepare them for being visualized.
Input data are downloaded from NOAA Significant Earthquake Database and embedded in the project.
file_read()
- Reads erthquake datafile_read()
is used to make reading input data more convenient. Although it can accept a fully qualified file name as an input parameter, by default it reads the data file embedded in the project:
NOAA <- file_read()
eq_get_date()
- Creates a date from its numeric representation -eq_get_date()
could be easily replaced with other functions like ISOdate()
for AD dates but it is much more difficult for BC ones. That is where eq_get_date()
does its job. It has a problem with producing BC leap days (actually the core problem is in R, which believes that it was 0-th year which started AD era) but there are no such dates in the data set. Let me show how it works:
eq_get_date(2018, 05, 20); eq_get_date(-2070, 07, 12); eq_get_date(2000);
It returns the object of the POSIXct
class
lubridate::year(eq_get_date(-2070, 07, 12))
eq_location_clean()
- Cleans the LOCATION_NAME columnThis function helps to clean the LOCATION_NAME column by stripping out the country name (including the colon) and converts names to title case (as opposed to all caps). This will be needed later for annotating visualizations.
eq_location_clean("TURKEY: IZMIR, EFES")
eq_clean_data()
- Cleans NOAA dataThis function takes takes raw NOAA data frame and returns a clean data frame. Cleaning means the following:
DATE
column by uniting the year, month, day and converts it to the Date class (with the help of eq_get_date()
)LATITUDE
and LONGITUDE
columns to numeric classLOCATION_NAME
column by stripping out the country name (including the colon) and converts names to title case (with the help of eq_location_clean()
)NOAAC <- eq_clean_data(NOAA) knitr::kable(head(NOAAC, 5))
Now the data are clean and ready for being vizualized
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.