Overview

A brief description of the package PCR which is a capstone project for the coursera mastering software development in R specialization. Locating the dataset that is used to show the package functionality. Using the functions developed in the package to visualize parts of the data.

Loading and cleaning data

Including all the libraries to run the code.

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

A copy of the capstone dataset is included in this package and could 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("data", "dt.tsv", package = "PCR")
dt <- read_tsv(file_path) %>%
  eq_clean_date %>%
  eq_clean_location

Inspecting the first ten rows of the dataset and only the tidy columns that will be used in the subsequent visualization.

dt %>%
  slice(1:10) %>%
  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 1993 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.

dt %>%
  filter(COUNTRY == 'INDIA') %>%
  ggplot(aes(date = date,
               xmin = as.Date('1993-01-01'),
               xmax = as.Date('2000-12-31'),
               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.

dt %>%
  filter(COUNTRY %in% c('INDIA', 'IRAQ')) %>%
  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.

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


prathmeshchaudhari/PCR documentation built on May 3, 2019, 2:56 p.m.