The functions provided by this package use data from the U.S. National Oceanographic and Atmospheric Administration (NOAA) Significant Earthquake Database.
Currently, this package exists in a development version on GitHub. To use the package, you need to install it directly from GitHub using the install_github
function from devtools
.
You can use the following code to install the development version of jggEarthquake
:
library(devtools) install_github("grandez/jggEarthquake") library(jggEarthquake)
Users may access a sample dataframe by running the code below.
eq_data_raw
The raw data file for this data frame is in tab delimited format can be accessed (and saved to your currrent working directory) by running the following:
data_raw <-system.file("extdata", "signif.txt", package = "jggEarthquake") file.copy(from=c(data_raw),to=getwd()) data_raw_wd <- fread("./signif.txt")
According the requirements of project, following functions are available:
eq_get_data
eq_clean_data
eq_location_clean
geom_timeline
geom_timeline_label
But to simplify the use some wrappers has been added:
Takes the raw data set from NOAA server or from local system
# Download data set from Server data_raw <- eq_get_data() # Load data set from local data_raw_wd <- eq_get_data("inst/extdata/signif.txt")
Takes the raw data set and make it tidy. Include new fields; DATE, LATITUDE, LONGITUDE and RITCHER as primary magnitude
data_clean <- eq_clean_data(data_raw)
Takes the raw data set and modified the column LOCATION_NAME to strip out country names and reformats to title case. It is automatically called from eq_clean_data
data_loc = eq_location_clean(data_raw) ```` #### eq_load_data Wrapper to eq_get_data + eq_clean_data ```R # Download data set from Server data_clean <- eq_load_data() # Load data set from local data_clean <- eq_load_data("inst/extdata/signif.txt")
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.
Aesthetics supported:
ggplot(data_clean) + geom_timeline(aes(x=DATE,colour=DEATHS,fill=DEATHS,size=RITCHER, xmin = 2000,xmax = 2016 ) )
A ggplot2 graphical function to plot a timeline of earthquakes from cleaned data adding labels to n-largest earthquakes by magnitude.
Aesthetics supported:
ggplot(data_clean) + geom_timeline_label(aes(x=DATE, colour=DEATHS, fill=DEATHS, size=RITCHER, xmin = 2000, xmax = 2016,nmax = 5) )
A wrapper function to help generate timeline visualisations easier. Parameters:
eq_geom_timeline(eq_data_clean, xmin=0, xmax=2016, countries=c("USA", "CHINA"))
A wrapper function to help generate timeline with labels visualisations easier.
Parameters:
eq_geom_timeline_label(eq_data_clean ,xmin=0 ,xmax=2016 ,n_max=5 ,countries=c("USA", "CHINA"))
A function to generate an interactive map showing earthquakes for a particular country. The user specifies a column from the data which the earthquake is to be annotated by eg date.
eq_clean_data(eq_data_raw) %>% dplyr::filter(COUNTRY == "MEXICO" & lubridate::year(date) >= 2000) %>% eq_map(annot_col="date")
A function to generate a custom popup box for a selected earthquake showing location, magnitude and total deaths.
eq_clean_data(eq_data_raw) %>% eq_location_clean() %>% dplyr::filter(COUNTRY == "MEXICO" & lubridate::year(date) >= 2000) %>% dplyr::mutate(popup_text = eq_create_label(.)) %>% eq_map(annot_col="popup_text")
The package also contains a new theme theme_timeline
for use with geom_timeline
and geom_timeline_label
. It is applied automatically when using get_timeline
and get_timeline_label
.
There are two custom grobs and a custom stat included with the package which are used by the geom_
functions. These are geomTimeline
, geomTimelineLabel
and StatTimeline
.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.