knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
This is a package developed exclusively for the purposes of R Capstone Project, a Webinar in Coursera. Its purpose is to help illustrate the NOAA Significant Earthquakes dataset, with two new geoms and an interactive leaflet map. Also, three functions are developed to help in the implementation of the geoms and the map.
This function takes a data frame, ideally from the NOAA Significant Earthquakes dataset, and creates a DATE column. It also coerses LATITUDE and LONGITUDE into numerics. This function is meant to be used in the geoms of this package, so it does not need to be exported.
library(earthquakes) load("data/data.rda") data<-eq_clean_data(data)
This function takes a data frame, ideally from the NOAA Significant Earthquakes dataset, and cleans the LOCATION_NAME column. Specifically, it deletes the name of the country, if there is one included in the string, leaving only the region name. It also changes the string into title case. This function is meant to be used in the geoms of this package, so it does not need to be exported.
library(earthquakes) load("data/data.rda") data<-eq_location_clean(data)
This geom depicts the earthquake data from the NOAA Significant Earthquakes dataset as a timeline with points for each earthquake. It works best if the user chooses to group the data by country.
library(earthquakes) library(dplyr) library(magrittr) library(ggplot2) # Read the data load("data/data.rda") # Subset the data for plotting examples data<-eq_clean_data(data) data<-eq_location_clean(data) data2<-data %>% filter(COUNTRY %in% c("USA", "CHINA")) ggplot(data2, aes(x=DATE, y=COUNTRY, size=EQ_PRIMARY, color=DEATHS)) + geom_timeline(alpha=0.3, xmin=as.Date("2012-01-01"), xmax=as.Date("2015-01-01")) + theme(axis.line.x = element_line(colour="black", size=1), axis.title.y=element_blank(), legend.position="bottom", panel.background=element_blank())+ labs(size="Richter scale value", color="# deaths")
This geom adds the earthquake location name, from the NOAA Significant Earthquakes dataset, The user can choose the number of the earthquake labels to appear in the plot. It works best in conjuction with the geom_timeline().
library(earthquakes) library(dplyr) library(magrittr) library(ggplot2) # Read the data load("data/data.rda") # Subset the data for plotting examples data<-eq_clean_data(data) data<-eq_location_clean(data) data2<-data %>% filter(COUNTRY %in% c("USA", "CHINA")) ggplot(data2, aes(x=DATE, y=COUNTRY, size=EQ_PRIMARY, color=DEATHS, label=LOCATION_NAME, magnitude=EQ_PRIMARY)) + geom_timeline(alpha=0.3, xmin=as.Date("2000-01-01"), xmax=as.Date("2017-01-01")) + geom_timeline_label(xmin=as.Date("2000-01-01"), xmax=as.Date("2015-01-01"), n_max=5)+ theme(axis.line.x = element_line(colour="black", size=1), axis.title.y=element_blank(), legend.position="bottom", panel.background=element_blank())+ labs(size="Richter scale value", color="# deaths")
This function creates an interactive map that shows the location of the earthquakes in the NOAA Significant Earthquakes dataset. The locations are depicted in circular markers which pop-up more information about the earthquakes, if selected. The following example may not appear interactive.
library(earthquakes) library(dplyr) library(magrittr) # Read the data load("data/data.rda") data %>% eq_clean_data() %>% dplyr::filter(COUNTRY == "MEXICO" & lubridate::year(DATE) >= 2000) %>% eq_map(annot_col = "DATE")
This function creates detailed labels for the interactive map, so that the pop-up markers include more information (Location name, magnitude of the earthquake and number of victims) about the earthquakes. The following example may not appear interactive.
library(earthquakes) library(dplyr) library(magrittr) library(lubridate) # Read the data load("data/data.rda") data %>% eq_clean_data() %>% dplyr::filter(COUNTRY == "MEXICO" & lubridate::year(DATE) >= 2000) %>% dplyr::mutate(popup_text = eq_create_label(.)) %>% eq_map(annot_col = "popup_text")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.