FooR

J. Antonio García, jose.ramirez@cimat.mx

2018-01-12

This vignette two process: - Cleaning - Two different visualizations (over time - like Doctor Who would see it - and country)

About the NOAA earthquake data. the data come can be obtained from NOAA Significant Earthquake Database.

Package content

There are ten functions within the package:

But only the following functions are exported:

Data

The package contains the dataset obtained from National Geophysical Data Center / World Data Service (NGDC/WDS): Significant Earthquake Database. National Geophysical Data Center, data. doi:10.7289/V5TD9V7K consulted on the date “12 January, 2018” and and obviously the dataset is called data

filename <- system.file("extdata/signif.txt", package = "FooR")
data <- readr::read_tsv(filename)
data <- eq_clean_data(data)
I_D FLAG_TSUNAMI YEAR MONTH DAY HOUR MINUTE SECOND
1 NA -2150 NA NA NA NA
3 NA -2000 NA NA NA NA NA
FOCAL_DEPTH EQ_PRIMARY EQ_MAG_MW EQ_MAG_MS EQ_MAG_MB EQ_MAG_ML
NA 7.3 NA NA NA NA
  18           7.1          NA          7.1         NA          NA     

EQ_MAG_MFA EQ_MAG_UNK INTENSITY COUNTRY STATE
NA 7.3 NA JORDAN NA
NA NA 10 TURKMENISTAN NA
LOCATION_NAME
JORDAN: BAB-A-DARAA,AL-KARAK
TURKMENISTAN: W

Data cleaning

It is evident that the data set has numerous columns with null or missing values, although a future and interesting work for this package would be to apply data imputation techniques to the dataset . For the above you can use the function eq_clean_data() and eq_location_clean()

Visualization of earthquakes by time and place :

  1. Doctor-Who‘s view ( or style1), all the time and all the countries at once. You can visualize earthquakes in all dataset’s time variable YEAR without filter by the columns COUNTRY and YEAR and using the package ggplot and the recently implemented geom_, geom_timeline and geom_timeline_label. (you must pay attention with the column so that the visualization is of a suitable size and not empty, as in every ggplot´s function, one must have congruent with the variables’ name of the dataset and the parameters of ggplot2::aes function.)1
data %>%
filter( DEATHS>0) %>%
     ggplot(aes(x = Date,
                y = COUNTRY,
                color = DEATHS,
                size = as.numeric(EQ_PRIMARY)
     )) +
     geom_timeline() +
     #geom_timeline_label(aes(label = LOCATION_NAME)) +
     theme_timeline() +
     labs(size = "Richter scale value", color = "# deaths",
          title = "Figure 1 : Doctor Who's view")

  1. No-Doctor-Who’s (style2), not all the time neither all the countries at once. You can visualize earthquakes in a single country after filter by the column COUNTRY or many others, (you must pay attention with the columns of YEAR and DEATHS so that the visualization is of a suitable size and not empty, as in every ggplot´s function, one must have congruent with the variables’ name of the dataset and the parameters of ggplot2::aes function.)
data %>%
filter(COUNTRY %in% c("USA"), 2020 > YEAR,  YEAR > 2000, DEATHS>0) %>%
     ggplot(aes(x = Date,
                y = COUNTRY,
                color = DEATHS,
                size = as.numeric(EQ_PRIMARY)
     )) +
     geom_timeline() +
     geom_timeline_label(aes(label = LOCATION_NAME)) +
     theme_timeline() +
     labs(size = "Richter scale value", color = "# deaths",
     title = "Figure 2: Human vision")

  1. Style3, not all the time neither all the countries at once. You can visualize earthquakes in a single country after filter by the column COUNTRY or many others, (you must pay attention with the columns of YEAR and DEATHS as in style2)
data %>%
filter(COUNTRY %in% c("USA", "MEXICO", "JAPAN"), 2020 > YEAR,  YEAR > 2000, DEATHS>0) %>%
     ggplot(aes(x = Date,
                y = COUNTRY,
                color = DEATHS,
                size = as.numeric(EQ_PRIMARY)
     )) +
     geom_timeline() +
     geom_timeline_label(aes(label = LOCATION_NAME)) +
     theme_timeline() +
     labs(size = "Richter scale value", color = "# deaths",
     title = "Figure 3: Human vision")

Visualize earthquakes on a pretty map

Using the leaflet package it is very easy to make beautiful interactive maps using the function eq_map().There are two options to use this function one without using the function eq_create_label() from where we get the following map:

data %>% 
   dplyr::filter(COUNTRY == "MEXICO" & lubridate::year(Date) >= 2000) %>% 
  eq_map(annot_col = "Date")

And the other one using it

data %>%
 dplyr::filter(COUNTRY == "MEXICO" & lubridate::year(Date) >= 2000) %>% 
  dplyr::mutate(popup_text = eq_create_label(.)) %>% 
  eq_map(annot_col = "popup_text")

  1. Thanks to my brother and my friend Claudia for the idea about figure 1.