Skip to content

Commit 1ca9f32

Browse files
committed
Final Commit before Submission
1 parent 6922244 commit 1ca9f32

File tree

8 files changed

+3186
-64
lines changed

8 files changed

+3186
-64
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.Rhistory
33
.RData
44
.Ruserdata
5+
test.md

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,5 @@ The NOAA Storm Database receives Storm Data from the National Weather Service fr
1111

1212
This work was done as a part of a project towards the completion of the [Reproducible Research](http://www.coursera.org/learn/reproducible-research) course in the [Data Science Specialization](http://www.coursera.org/specializations/jhu-data-science). This `knitr` generated publication documents all the work done (in R) towards the completion of said project.
1313

14+
-------------------------
1415
**Read the full [data documentation](https://d396qusza40orc.cloudfront.net/repdata%2Fpeer2_doc%2Fpd01016005curr.pdf)**
15-
16-
-----------------
17-
*Done towards the completion of the [Reproducible Research](https://www.coursera.org/learn/reproducible-research) course by Johns Hopkins University.*

RMArkdown.Rmd

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ output:
1212
df_print: paged
1313
highlight: tango
1414
---
15+
<a href="https://github.com/RexGalilae/Weather-Data-Rmd" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
16+
1517
## Synopsis
1618

17-
```{r image-render, echo=FALSE, fig.align="center", fig.width=6, cache=TRUE}
19+
```{r image-render, echo=FALSE, fig.align="center", fig.width=6, cache=TRUE, fig.cap="A photo of Hurricane Florence taken from the ISS (Courtesy: NASA)"}
1820
library(jpeg)
1921
library(grid)
2022
img <- readJPEG("hurriet-pasha.jpg")
@@ -40,8 +42,8 @@ library(knitr)
4042
library(xtable)
4143
library(magrittr)
4244
library(data.table)
43-
library(rapportools)
44-
library(wesanderson)
45+
library(waffle)
46+
library(RColorBrewer)
4547
4648
knitr::opts_chunk$set(
4749
fig.align = "center",
@@ -128,7 +130,7 @@ unique(dmg$CROPDMGEXP)
128130
Corresponding to each unique symbol, we need to assign a numeric value. Let's create key-value pairs with our assigned exponents as values to facilitate our transition from this current state (shown [here](#curr)) to [this](#ideal).
129131

130132
### 1. Change all `xEXP` entries to uppercase.
131-
```{r to-upper, cache=FALSE}
133+
```{r to-upper, cache=TRUE}
132134
cols <- c("PROPDMGEXP", "CROPDMGEXP")
133135
dmg %<>% mutate_at(cols, toupper)
134136
dmg <- as.data.table(dmg)
@@ -170,10 +172,10 @@ dmg[is.na(PROPDMGEXP), PROPDMGEXP := 10^0 ]
170172
dmg[, CROPDMGEXP := cropDmgKey[as.character(dmg[,CROPDMGEXP])] ]
171173
dmg[is.na(CROPDMGEXP), CROPDMGEXP := 10^0 ]
172174
```
173-
*NOTE:* Using `mutate_at` along with a key-value fetcher function for this task doesn't work as intended and instead, copies the same values across all rows.
175+
*NOTE:* Using `mutate_at` along with a key-value fetcher function for this task didn't work as intended and instead, copied the same values across all rows. This is why it was avoided in this chunk.
174176

175177
### 4. Use `mutate` to create columns for `PropertyDamage`, `CropDamage` and `TotalDamage` and get rid of the raw column data
176-
```{r calc-dmg, cache=FALSE}
178+
```{r calc-dmg, cache=TRUE}
177179
dmg %<>%
178180
mutate(PropertyDamage = PROPDMG*PROPDMGEXP, CropDamage = CROPDMG*CROPDMGEXP) %>%
179181
mutate(TotalDamage = PropertyDamage+CropDamage, TotalCasualties = FATALITIES+INJURIES) %>%
@@ -232,26 +234,29 @@ humanLosses <- melt(humanLosses)
232234

233235
### Plotting
234236

235-
```{r hloss-bar}
237+
```{r hloss-bar, fig.cap="A Bar Plot of the Top 10 Events with the Most Reported Casualties"}
236238
# Specify Aesthetic mappings
237239
plot <- ggplot(humanLosses, aes(x = reorder(EVTYPE, -value), y= value, fill= variable))
238240
239241
# Specify Bar Chart specs
240242
plot = plot + geom_bar(stat = "identity", position = "dodge")
241243
244+
# Set x-axis label to blank
245+
plot = plot + xlab(element_blank())
246+
242247
# Set y-axis label
243248
plot = plot + ylab("Casualties")
244249
245-
# Prevent clutter
246-
plot = plot + theme(axis.text.x = element_text(angle=45, hjust=1))
250+
# Prevent clutter around the x-axis
251+
plot = plot + theme(axis.text.x = element_text(angle=45, hjust=1), axis.title.x = element_blank())
247252
248253
# Set chart title and center it
249254
plot = plot + ggtitle("Top 10 Deadliest Events") + theme(plot.title = element_text(hjust = 0.5))
250255
251256
plot
252257
```
253258

254-
```{r eloss-bar}
259+
```{r eloss-bar, fig.cap="A Bar Plot of the Top 10 Costliest Types of Weather Events"}
255260
# Specify Aesthetic mappings
256261
plot <- ggplot(econLosses, aes(x = reorder(EVTYPE, -value), y= value, fill= variable))
257262
@@ -261,24 +266,24 @@ plot = plot + geom_bar(stat = "identity", position = "dodge")
261266
# Set y-axis label
262267
plot = plot + ylab("Cost ($)")
263268
264-
# Prevent clutter
265-
plot = plot + theme(axis.text.x = element_text(angle=45, hjust=1))
269+
# Prevent clutter around the x-axis
270+
plot = plot + theme(axis.text.x = element_text(angle=45, hjust=1), axis.title.x = element_blank())
266271
267272
# Set chart title and center it
268273
plot = plot + ggtitle("Top 10 Costliest Events") + theme(plot.title = element_text(hjust = 0.5))
269274
270275
plot
271276
```
272277

273-
While a bar plot pretty much nails it when it comes to comparing events on absolute terms, a relative comparison of Total Losses using a "Waffle" Chart might be better for most situations.
278+
The data for Casualties is pretty clear on what the major contributor to weather-event related deaths is with Tornados taking a sizeable lead over the rest in both Injuries as well as Fatalities. The following four events are tied pretty evenly with each other while the events further down the list start appearing progressively insignificant next to one another.
274279

275-
First, re-abbreviate the data to only include the Total Losses of each category
280+
On the other hand, the data on Economic Costs a steady progression a la [Zipf's Law](https://en.wikipedia.org/wiki/Zipf%27s_law) with Floods still holding an indisputable lead over damages to Property and Crops with Typhoon and Tornados (no less) not very far behind. Interestingly, one may also notice that a few Events show extreme selectivity towards one type of Economic Resource. Upon closer inspection, however, it seems obvious why.
276281

277-
```{r re-summarize}
278-
totalhumanLosses <- humanLosses[as.character(humanLosses$variable) == "TotalCasualties",c("EVTYPE","value")]
279-
totaleconLosses <- econLosses[as.character(econLosses$variable) == "TotalDamage",c("EVTYPE","value")]
280-
```
282+
## Concluding Words
281283

282-
```{r waffle}
284+
This work was done as a part of a project towards the completion of the [Reproducible Research](http://www.coursera.org/learn/reproducible-research) course in the [Data Science Specialization](http://www.coursera.org/specializations/jhu-data-science).
283285

284-
```
286+
Keeping focus and familiarity in mind,I went with the `readthedocs`-esque layout available for `Rmd` courtesy of [juba](https://github.com/juba/rmdformats). I've made my full code available on [github](https://github.com/RexGalilae/Weather-Data-Rmd). If there are any suggestions, feel free to make them `r emo::ji("smile")`
287+
288+
-------------------------------------------------------------
289+
*Created by Zaid Hassan aka alhazen on `r Sys.Date()`*

RMArkdown.html

Lines changed: 112 additions & 26 deletions
Large diffs are not rendered by default.

RMArkdown.md

Lines changed: 123 additions & 15 deletions
Large diffs are not rendered by default.

Weather-Data-Rmd.Rproj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Version: 1.0
2+
3+
RestoreWorkspace: Default
4+
SaveWorkspace: Default
5+
AlwaysSaveHistory: Default
6+
7+
EnableCodeIndexing: Yes
8+
UseSpacesForTab: Yes
9+
NumSpacesForTab: 8
10+
Encoding: UTF-8
11+
12+
RnwWeave: Sweave
13+
LaTeX: pdfLaTeX

test.Rmd

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
title: "Weather Events and their Impacts on Human Health and Economics"
3+
date: "`r Sys.Date()`"
4+
author: "Zaid Hassan"
5+
output:
6+
rmdformats::readthedown:
7+
code_folding: show
8+
self_contained: true
9+
thumbnails: false
10+
lightbox: true
11+
keep_md: yes
12+
df_print: paged
13+
highlight: tango
14+
---
15+
16+
<a href="https://your-url" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; left: 0; transform: scale(-1, 1);" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style></a>
17+
18+
```{r setup, include=FALSE}
19+
knitr::opts_chunk$set(echo = TRUE)
20+
```
21+
22+
## R Markdown
23+
24+
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
25+
26+
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
27+
28+
```{r cars}
29+
summary(cars)
30+
```
31+
32+
## Including Plots
33+
34+
You can also embed plots, for example:
35+
36+
```{r pressure, echo=FALSE}
37+
plot(pressure)
38+
```
39+
40+
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

test.html

Lines changed: 2871 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)