knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(magrittr)
library(dplyr)
library(readr)
library(kableExtra)
library(Rcapstone)
library(ggplot2)

Table of Contents

1. Introduction {#intro}

The geom_timeline is a new geom_* of ggplot2 package that aims to enhance the visualization of earthquake. This Geom has some configuration:

Example 1 {#example_1}

Let's plot the earthquake from 1000 to 2000, which occured in JAPAN.

# Path to the raw data.
raw_data_path <- system.file("extdata", "signif.txt", package = "Rcapstone")

# Loading the dataset of Earthquake.
df <- readr::read_delim(file = raw_data_path,      
                        delim = '\t',              
                        col_names = TRUE,          
                        progress = FALSE,           
                        col_types = readr::cols())

# Cleaning the data and filtering.
df %>% 
       eq_clean_data() %>%

              filter(COUNTRY %in% 'JAPAN',
                     YEAR >= 1000 &
                     YEAR <= 2000) %>%
              # Creating a ggplot object
              ggplot() + 
                     # Using the new Geom
                     geom_timeline(aes(x     = DATE,
                                       y     = COUNTRY,
                                       size  = EQ_PRIMARY,
                                       color = TOTAL_DEATHS)) +
                            # Adding theme.
                            theme_Rcapstone() + 
                                   # Editing the legends' titles 
                                   labs(size = "Richter scale value",
                                        color = "# deaths")

Most of earthquake records in Japan are concentrated between 1900 and 2000.

Example 2 {#example_2}

The earthquake record of 2018. Simple comparison.

# List of countries in Europe and "West Asia". This is not an exhaustive list.
eurasia <- c('SPAIN','GREECE','TURKEY','PORTUGAL','RUSSIA','FRANCE','MACEDONIA','BULGARIA',
             'ALBANIA','GEORGIA','ITALY','SLOVENIA','UK','CYPRUS','UKRAINE','CROATIA','AUSTRIA')

# Cleaninig data and filtering.
df %>% 
       eq_clean_data() %>%
              # Creating a new feature.
              mutate(CONTINENT = case_when(COUNTRY %in% eurasia ~ "EURASIA",
                                          !(COUNTRY %in% eurasia) ~ "WORLD")) %>%
                     # Filtering.
                     filter(YEAR >= 2018 &
                            YEAR <= 2019) %>%

                            # Creating a ggplot object
                            ggplot() + 
                                   # Using the new Geom
                                   geom_timeline(aes(x     = DATE,
                                                     y     = CONTINENT,
                                                     size  = EQ_PRIMARY,
                                                     color = TOTAL_DEATHS)) +
                                          # Adding theme.
                                          theme_Rcapstone() + 
                                                 # Editing the legends' titles 
                                                 labs(size = "Richter scale value",
                                                      color = "# deaths")


hsuzero/Rcapstone documentation built on Dec. 20, 2021, 4:50 p.m.