-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
142 lines (112 loc) · 5.12 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
---
output: github_document
---
<!--
README.md is generated from README.Rmd, so you should edit that file.
-->
```{r, echo = FALSE}
knitr::opts_chunk$set(collapse = TRUE,
comment = ">",
fig.path = "man/figures/README-",
fig.align = "center",
fig.height = 6,
fig.width = 9,
message = FALSE, warning = FALSE)
```
# rnoaa <img src="man/figures/logo.png" align="right" width="120"/>
[![Travis Build Status](https://travis-ci.org/Cesar-Urteaga/rnoaa.svg?branch=master)](https://travis-ci.org/Cesar-Urteaga/rnoaa)
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/Cesar-Urteaga/rnoaa?branch=master&svg=true)](https://ci.appveyor.com/project/Cesar-Urteaga/rnoaa)
[![codecov](https://codecov.io/gh/Cesar-Urteaga/rnoaa/branch/master/graph/badge.svg)](https://codecov.io/gh/Cesar-Urteaga/rnoaa)
## Table of Contents
* [Overview](#overview)
* [Installation](#installation)
* [Usage](#usage)
* [Documentation](#documentation)
* [Unit Testing](#unit-testing)
* [Development Workflow](#development-workflow)
## Overview
`rnoaa` is an [R](https://www.r-project.org/) package with a set of functions that makes easier to analyze the earthquake data provided by the [U.S. National Oceanic and Atmospheric Administration (NOAA)](http://www.noaa.gov/).
## Installation
```{r, eval = FALSE}
# Install the package from GitHub without the vignette:
devtools::install_github("Cesar-Urteaga/rnoaa")
# Or you can include it:
devtools::install_github("Cesar-Urteaga/rnoaa", build_vignettes = TRUE)
```
## Usage
This package allows you to get and clean the latest earthquake data from [the NOAA's Webpage](https://www.ngdc.noaa.gov/nndc/struts/form?t=101650&s=1&d=1) so as to prepare it for analysis:
```{r}
library(rnoaa)
library(dplyr)
# GETTING THE DATA
# In case you do not have internet access, you can use the get_earthquake_data
# function, which is a snapshot of the quake's data on September 10, 2017:
# raw_data <- get_earthquake_data()
raw_data <- download_earthquake_data()
# TIDYING THE DATA UP
# Before the data has been processed:
set.seed(48)
raw_data %>%
select(YEAR, MONTH, DAY, COUNTRY, LOCATION_NAME) %>%
sample_n(6)
# We use the two rnoaa's functions to clean the data.
clean_data <- raw_data %>%
eq_clean_data() %>%
eq_location_clean()
# After the data has been processed (note that the DATE variable has been
# created and the country has been removed for the LOCATION_NAME variable):
set.seed(48)
clean_data %>%
select(YEAR, MONTH, DAY, DATE, COUNTRY, LOCATION_NAME) %>%
sample_n(6)
# N.B.: When the month or/and day is/are missing, the date is approximated
# at the midpoint of the period.
```
Once the data was tidied, `rnoaa` includes two ggplot2's geoms to visualize the timeline in which the quakes have ocurred and label the ones with the greatest magnitude:
```{r TimelineGeom}
library(ggplot2)
clean_data %>%
filter(COUNTRY %in% c("CANADA", "USA", "MEXICO",
"CHINA", "JAPAN", "INDIA"),
!is.na(EQ_PRIMARY),
YEAR %in% 2000:2016) %>%
ggplot(mapping = aes(x = DATE,
y = COUNTRY,
size = EQ_PRIMARY,
color = TOTAL_DEATHS / 1000,
label = LOCATION_NAME)
) +
geom_timeline() +
geom_timeline_label(# We want to show the label for at most the two highest
# earthquakes by size.
n_max = 2,
line_height = 1 / 4,
angle = 10,
fontsize = 2.5) +
labs(size = "Richter scale value",
color = "# deaths in thousands",
y = "") +
guides(size = FALSE) +
theme_timeline()
```
Furthermore, it provides with functions to display the epicenters in an interactive R leaflet map:
```{r, eval = FALSE}
clean_data %>%
dplyr::filter(COUNTRY == "JAPAN" & lubridate::year(DATE) >= 2000) %>%
eq_map(annot_col = "DATE")
```
![](./man/figures/README-LeafletMap-1.png?raw=true)
Also, it assists you to display the quake's traits from the data using popup text labels:
```{r, eval = FALSE}
clean_data %>%
dplyr::filter(COUNTRY == "MEXICO" & lubridate::year(DATE) == 2017) %>%
dplyr::mutate(popup_text = eq_create_label(.)) %>%
eq_map(annot_col = "popup_text")
```
![](./man/figures/README-LeafletMap-2.png?raw=true)
## Documentation
Please check the [package's vignette](./vignettes/using-rnoaa.Rmd) to see how the package works or review the examples given in the package's documentation (use `?function_name`); you can run them with the function `example` (e.g., `example("geom_timeline_label")`).
## Unit Testing
In order to increase the quality of the package, a [test suite](./tests/testthat) was carried out for each function using the `testthat` R package. I have added a [code coverage](https://en.wikipedia.org/wiki/Code_coverage) measure to the package's repository using [codecov](https://codecov.io).
## Development Workflow
The workflow that was used to develop this package is described [here](https://github.com/Cesar-Urteaga/rfars#workflow).