knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Function and data from buildingpackage package would be useful to show information about history of earthquake around the world.

To do that, it provide a raw version of the NOAA Significant Earthquake DatabaseD.

library(buildingpackage)
requireNamespace("DT", quietly = TRUE)
requireNamespace("lubridate", quietly = TRUE)
requireNamespace("ggplot2", quietly = TRUE)
library(devrcap)
    data("noaa")
DT::datatable(noaa)

The first function implemented would be used to clean this database and prepare it for further analyses and visualizations.

More in details, the function eq_clean_data() produce a dataset with the following characteristics:

data_cleaned <- devrcap::eq_clean_data(noaa) 
DT::datatable(data_cleaned)

Using the ggplot2 geom geom_timeline() provided by devrcap, we can use the cleaned data to plot time lines of earthquakes both overall and by group (e.g., country).

Moreover, using geom_timeline_label() we can add information about the earthquakes, e.g. the location. Due to the possible huge ammount of information that could be displayed, an option n_max can be used to limit the ammount of information to show. If the size option is also provided to ggplot, the n_max option will show the n_max largest earthquakes (otherwise it will be simply sample n_max earthquakes at random to show the information about the location)

noaa %>%
    eq_clean_data() %>%
    dplyr::filter(
        country %in% c("ITALY", "GREECE", "PORTUGAL"),
        lubridate::year(date) >= 1900
    ) %>%
    ggplot2::ggplot(ggplot2::aes(
        x = date,
        y = country,
        size   = eq_primary,
        colour = log(total_deaths),
        label  = location_name
    )) +
    geom_timeline() +
    geom_timeline_label(n_max = 3) +
    ggplot2::theme(legend.position = "bottom")

Using the funciton eq_map() we can also show an interactive map of earthquakes, and with the functionality added by the function eq_create_label() we can also show (interactively) information (when present) about location, magnitude and total death of each earthquakes.

noaa %>%
    eq_clean_data %>%
    dplyr::filter(
        country == "MEXICO",
        lubridate::year(date) >= 2000
    ) %>%
    dplyr::mutate(popup_text = eq_create_label(.)) %>%
    eq_map("popup_text")


sheila-NAA/Mastering-software-development documentation built on Dec. 23, 2021, 1:22 a.m.