library(capstoneJH) library(dplyr) library(ggplot2) library(readr)
There are six exported functions available to users:
eq_clean_data()
geom_timeline()
geom_timeline_label()
theme_timeline()
eq_create_label()
eq_map()
Data from NOAA can be found in the package directory under \extdata
folder.
The first function is required to clean data for the visualization. It creates a DATE column in Date
format, transforms latitude and longitude to numeric format and trims country from LOCATION_NAME.
filename <- system.file("extdata/earthquakes.tsv.gz", package = "capstoneJH") data <- readr::read_delim(filename, delim = "\t") eq_clean_data(data)
The geom_timeline()
requires clean data.
data %>% eq_clean_data() %>% filter(COUNTRY %in% c("GREECE", "ITALY"), YEAR > 2000) %>% ggplot(aes(x = DATE, y = COUNTRY, color = as.numeric(TOTAL_DEATHS), size = as.numeric(EQ_PRIMARY) )) + geom_timeline() + geom_timeline_label(aes(label = LOCATION_NAME), n_max = 5) + theme_timeline() + labs(size = "Richter scale value", color = "# deaths")
The package utilized leaflet
functions to visualize earthquakes on a map using eq_map()
function. The map is automatically trimmed to display the input data frame. Optional annotations can be created using eq_create_label()
function. The result is an interactive map where user can click on individual points to get details:
data %>% eq_clean_data() %>% dplyr::filter(COUNTRY == "GREECE" & lubridate::year(DATE) >= 1990) %>% 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.