The NOAAeq
package analyses data from the Significant Earthquake Database of the U.S. National Oceanographic and Atmospheric Administration (NOAA). This dataset contains information about 5,933 earthquakes over an approximately 4,000 year time span.
require("knitr") require("NOAAeq") require("magrittr") opts_knit$set(root.dir = system.file("extdata", package = "NOAAeq"))
data <- readr::read_delim(file = "earthquakes.tsv.gz", delim = "\t")
Location names can be cleaned to ensure a nice display as labels in timeline plots and maps.
eq_location_clean(c("MEXICO: MICHOACAN", "SWITZERLAND: BASEL", "THAILAND: BANGKOK"))
This function is called within the eq_clean_data
function.
Timelines need information on dates. Therefore, temporal information, such as year, month, and day, have to be united and converted to a date format. In addition, several columns have to be converted to numeric to ensure their usability in plotting functions.
data %>% eq_clean_data()
Timelines visualize temporal information. Each point symbol represents one earthquake. Additional information about the earthquakes can be displayed as the size or colour of the point symbols.
data %>% eq_clean_data() %>% dplyr::filter(lubridate::year(DATE) %in% 2000:2017 & COUNTRY == "USA") %>% ggplot(aes(x = DATE, size = EQ_PRIMARY, fill = TOTAL_DEATHS)) + geom_timeline() + theme_classic() + theme(legend.position = "bottom") + scale_size_continuous(name = "Richter scale value") + scale_fill_continuous(name = "# deaths") + guides(size = guide_legend(order = 1), fill = guide_colourbar(order = 2))
Adding labels to the earthquakes allows to identify them. For better readability, it is recommended to limit the number labels to earthquakes of special interest. Furthermore, the timelines of multiple groups (e.g. countries) can easily be compared by stratification.
data %>% eq_clean_data() %>% dplyr::filter(lubridate::year(DATE) %in% 2000:2017 & COUNTRY %in% c("USA", "CHINA")) %>% ggplot(aes(x = DATE, y = COUNTRY, fill = TOTAL_DEATHS)) + geom_timeline() + geom_timeline_label(aes(label = LOCATION_NAME, col_max = EQ_PRIMARY), n_max = 5) + theme_classic() + theme(legend.position = "bottom", axis.title.y = element_blank(), axis.ticks.y = element_blank(), axis.line.y = element_blank()) + scale_fill_continuous(name = "# deaths", breaks = c(1, 87652))
Besides visualizing the earthquakes in time, it’s important that we can visualize them in space. An interactive map additionally allows to click on earthquake markers and retrieve further information from a pop-up window.
data %>% eq_clean_data() %>% dplyr::filter(COUNTRY == "MEXICO" & lubridate::year(DATE) >= 2000) %>% eq_map(annot_col = "DATE")
The information provided in the pop-up window can be further customized.
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.