This is an R package to analyse the data "NOAA Significant Earthquake Database" in Capstone Sofware Development in R.
eq_clean_data
and eq_location_clean
functions clean the NOAA data frame: eq_map
function maps the earthquakes epicenters (LATITUDE/LONGITUDE) with the desired annotationeq_create_label
function that creates an HTML label for Location, Total deaths, and Magnitude in the leaflet map.geom_timeline
function visualizes the times, the magnitudes and the number of deaths corresponding to earthquakes within a given countries respectively, while the geom_timelinelabel
adds annotations to the earthquake .Download the data signif.txt from the NOAA website, put it to your working directory and transform it to a data frame using the read_delim
function:
library(readr) data <- readr::read_delim("signif.txt", delim = "\t")
Then clean the data with the functions eq_clean_data
and eq_location_clean
.
clean_data <- eq_clean_data(data) clean_data <- eq_location_clean(clean_data)
To map the earthquakes epicenters in Canada since 2000 and get their dates in annotation use the eq_map
function.
clean_data %>% dplyr::filter(COUNTRY == "CANADA" & lubridate::year(DATE) >= 2000) %>% eq_map(annot_col = "DATE")
To get annotation the Location, Total deaths, and Magnitude of the earthquakes, use the eq_create_label
function before the eq_map
function.
clean_data %>% dplyr::filter(COUNTRY == "CANADA" & lubridate::year(DATE) >= 2000) %>% dplyr::mutate(popup_text = eq_create_label(.)) %>% eq_map(annot_col = "popup_text")
To visualize times, magnitudes of earthquakes in Canada and USA, we use the geom_timeline
geom.
data %>% dplyr::filter(COUNTRY == c("CANADA","USA") & lubridate::year(DATE) >= 2010) %>% ggplot(aes(x=DATE,y=COUNTRY,color=TOTAL_DEATHS,size=EQ_PRIMARY)) + geom_timeline(alpha=.5) + theme(legend.position="bottom", legend.box="horizontal", plot.title=element_text(hjust=0.5)) + ggtitle("Earthquakes")
To add annotations to the earthquake data, we use geom_timelinelabel
geom
data %>% dplyr::filter(COUNTRY == c("CANADA","USA") & lubridate::year(DATE) >= 2010) %>% ggplot(aes(x=DATE,y=COUNTRY,color=TOTAL_DEATHS,size=EQ_PRIMARY)) + geom_timeline(alpha=.5) + geom_timelinelabel(aes(label=LOCATION_NAME),n_max=3) + theme(legend.position="bottom", legend.box="horizontal", plot.title=element_text(hjust=0.5)) + ggtitle("Earthquakes")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.