Overview

The following vignette is a brief discreption of the package MSDR which is a capstone project for the coursera mastering software development in R specilaization. I start by locating the dataset that is used to show the package functionality. Then, I use the functions developed in the pacakge to visualize parts of the data.

Loading and cleaning data

We start first by loading the libraries that are needed to run the followin codes.

library(dplyr)
library(readr)
library(ggplot2)
library(lubridate)
library(leaflet)
library(MSDR)

A copy of the capstone dataset is included in this package and coult be located and loaded using the following chunk of code. In addition, the package provides two helper function to tidy up the date and the location columns.

file_path <- system.file("extdata", "signif.tsv", package = "MSDR")
signif <- read_tsv(file_path) %>%
  eq_clean_date %>%
  eq_clean_location

Here, I inspect the first five rows of the dataset and only the tidy columns that will be used in the subsequent visualization.

signif %>%
  slice(1:5) %>%
  select(date, LOCATION, COUNTRY, DEATHS, EQ_PRIMARY)

Visualization tools

The following chunck of code subjets the dataset to the earthquak events that happened in Mexico between the years 1990 and 2000. Individual events are mapped as points, different sizes correspond to the magnitude of the events and the colors to the total death due to these events.

signif %>%
  filter(COUNTRY == 'MEXICO') %>%
  ggplot(aes(date = date,
               xmin = as.Date('1995-01-01'),
               xmax = as.Date('2000-12-30'),
               y = COUNTRY,
               colour = DEATHS,
               fill = DEATHS,
               size = EQ_PRIMARY,
               location = LOCATION)) +
  geom_timeline() +
  geom_timeline_label() +
  theme(axis.line.y = element_blank(),
        axis.line.x = element_line(),
        axis.ticks.y = element_blank(),
        axis.text.y = element_blank(),
        axis.title.y = element_blank(),
        legend.position = 'bottom',
        panel.grid = element_blank(),
        panel.background = element_blank())

Now, the same kind of plot is used to visualize data from more than one country.

signif %>%
  filter(COUNTRY %in% c('IRAN', 'TURKEY')) %>%
  ggplot(aes(date = date,
               xmin = as.Date('2011-05-19'),
               xmax = as.Date('2013-05-11'),
               y = COUNTRY,
               colour = DEATHS,
               fill = DEATHS,
               size = EQ_PRIMARY,
               location = LOCATION)) +
  geom_timeline() +
  geom_timeline_label() +
  theme(axis.line.y = element_blank(),
        axis.line.x = element_line(),
        axis.ticks.y = element_blank(),
        axis.text.y = element_blank(),
        axis.title.y = element_blank(),
        legend.position = 'bottom',
        panel.grid = element_blank(),
        panel.background = element_blank())

Mapping tools

Now the same data are used to map events to their geographical location using interactive maps. For each individual event a pop-up with information about the location, magnitude and resulting deaths when available.

signif %>%
  filter(COUNTRY == 'MEXICO' & year(date) >= 2000) %>%
  mutate(popup_text = eq_create_label(.)) %>%
  eq_map()


MahShaaban/MSDR documentation built on May 22, 2019, 12:41 p.m.