Rpub Link: Click Here

Synopsis

Storms and other severe weather events can cause both public health and economic problems for communities and municipalities. Many severe events can result in fatalities, injuries, and property damage, and preventing such outcomes to the extent possible is a key concern.

This project involves exploring the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database. This database tracks characteristics of major storms and weather events in the United States, including when and where they occur, as well as estimates of any fatalities, injuries, and property damage.

Data Analysis shows that Tornado is the worst type of event that would cause the most harm with respect to population health. Tornado has also caused the worst economic consequences.

# Download file
setwd('C:/Users/TAT/Desktop/Coursera/Lectures/5) Reproducible Research/')

if(!dir.exists("Assignment 2")) {dir.create("Assignment 2")}
if(!file.exists("StormData.csv.bz2")){
    fileURL <- "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2"
    download.file(fileURL, destfile = "./Assignment 2/StormData.csv.bz2", method = "auto")
}

# Read file into R
storm <- read.csv("./Assignment 2/StormData.csv.bz2", header = T, sep = ",")

Data Processing

Check summary of data and number of NA for each variable. Variables with >80% NA are removed from the dataset.

# Check summary
summary(storm)
##     STATE__                  BGN_DATE             BGN_TIME     
##  Min.   : 1.0   5/25/2011 0:00:00:  1202   12:00:00 AM: 10163  
##  1st Qu.:19.0   4/27/2011 0:00:00:  1193   06:00:00 PM:  7350  
##  Median :30.0   6/9/2011 0:00:00 :  1030   04:00:00 PM:  7261  
##  Mean   :31.2   5/30/2004 0:00:00:  1016   05:00:00 PM:  6891  
##  3rd Qu.:45.0   4/4/2011 0:00:00 :  1009   12:00:00 PM:  6703  
##  Max.   :95.0   4/2/2006 0:00:00 :   981   03:00:00 PM:  6700  
##                 (Other)          :895866   (Other)    :857229  
##    TIME_ZONE          COUNTY           COUNTYNAME         STATE       
##  CST    :547493   Min.   :  0.0   JEFFERSON :  7840   TX     : 83728  
##  EST    :245558   1st Qu.: 31.0   WASHINGTON:  7603   KS     : 53440  
##  MST    : 68390   Median : 75.0   JACKSON   :  6660   OK     : 46802  
##  PST    : 28302   Mean   :100.6   FRANKLIN  :  6256   MO     : 35648  
##  AST    :  6360   3rd Qu.:131.0   LINCOLN   :  5937   IA     : 31069  
##  HST    :  2563   Max.   :873.0   MADISON   :  5632   NE     : 30271  
##  (Other):  3631                   (Other)   :862369   (Other):621339  
##                EVTYPE         BGN_RANGE           BGN_AZI      
##  HAIL             :288661   Min.   :   0.000          :547332  
##  TSTM WIND        :219940   1st Qu.:   0.000   N      : 86752  
##  THUNDERSTORM WIND: 82563   Median :   0.000   W      : 38446  
##  TORNADO          : 60652   Mean   :   1.484   S      : 37558  
##  FLASH FLOOD      : 54277   3rd Qu.:   1.000   E      : 33178  
##  FLOOD            : 25326   Max.   :3749.000   NW     : 24041  
##  (Other)          :170878                      (Other):134990  
##          BGN_LOCATI                  END_DATE             END_TIME     
##               :287743                    :243411              :238978  
##  COUNTYWIDE   : 19680   4/27/2011 0:00:00:  1214   06:00:00 PM:  9802  
##  Countywide   :   993   5/25/2011 0:00:00:  1196   05:00:00 PM:  8314  
##  SPRINGFIELD  :   843   6/9/2011 0:00:00 :  1021   04:00:00 PM:  8104  
##  SOUTH PORTION:   810   4/4/2011 0:00:00 :  1007   12:00:00 PM:  7483  
##  NORTH PORTION:   784   5/30/2004 0:00:00:   998   11:59:00 PM:  7184  
##  (Other)      :591444   (Other)          :653450   (Other)    :622432  
##    COUNTY_END COUNTYENDN       END_RANGE           END_AZI      
##  Min.   :0    Mode:logical   Min.   :  0.0000          :724837  
##  1st Qu.:0    NA's:902297    1st Qu.:  0.0000   N      : 28082  
##  Median :0                   Median :  0.0000   S      : 22510  
##  Mean   :0                   Mean   :  0.9862   W      : 20119  
##  3rd Qu.:0                   3rd Qu.:  0.0000   E      : 20047  
##  Max.   :0                   Max.   :925.0000   NE     : 14606  
##                                                 (Other): 72096  
##            END_LOCATI         LENGTH              WIDTH         
##                 :499225   Min.   :   0.0000   Min.   :   0.000  
##  COUNTYWIDE     : 19731   1st Qu.:   0.0000   1st Qu.:   0.000  
##  SOUTH PORTION  :   833   Median :   0.0000   Median :   0.000  
##  NORTH PORTION  :   780   Mean   :   0.2301   Mean   :   7.503  
##  CENTRAL PORTION:   617   3rd Qu.:   0.0000   3rd Qu.:   0.000  
##  SPRINGFIELD    :   575   Max.   :2315.0000   Max.   :4400.000  
##  (Other)        :380536                                         
##        F               MAG            FATALITIES          INJURIES        
##  Min.   :0.0      Min.   :    0.0   Min.   :  0.0000   Min.   :   0.0000  
##  1st Qu.:0.0      1st Qu.:    0.0   1st Qu.:  0.0000   1st Qu.:   0.0000  
##  Median :1.0      Median :   50.0   Median :  0.0000   Median :   0.0000  
##  Mean   :0.9      Mean   :   46.9   Mean   :  0.0168   Mean   :   0.1557  
##  3rd Qu.:1.0      3rd Qu.:   75.0   3rd Qu.:  0.0000   3rd Qu.:   0.0000  
##  Max.   :5.0      Max.   :22000.0   Max.   :583.0000   Max.   :1700.0000  
##  NA's   :843563                                                           
##     PROPDMG          PROPDMGEXP        CROPDMG          CROPDMGEXP    
##  Min.   :   0.00          :465934   Min.   :  0.000          :618413  
##  1st Qu.:   0.00   K      :424665   1st Qu.:  0.000   K      :281832  
##  Median :   0.00   M      : 11330   Median :  0.000   M      :  1994  
##  Mean   :  12.06   0      :   216   Mean   :  1.527   k      :    21  
##  3rd Qu.:   0.50   B      :    40   3rd Qu.:  0.000   0      :    19  
##  Max.   :5000.00   5      :    28   Max.   :990.000   B      :     9  
##                    (Other):    84                     (Other):     9  
##       WFO                                       STATEOFFIC    
##         :142069                                      :248769  
##  OUN    : 17393   TEXAS, North                       : 12193  
##  JAN    : 13889   ARKANSAS, Central and North Central: 11738  
##  LWX    : 13174   IOWA, Central                      : 11345  
##  PHI    : 12551   KANSAS, Southwest                  : 11212  
##  TSA    : 12483   GEORGIA, North and Central         : 11120  
##  (Other):690738   (Other)                            :595920  
##                                                                                                                                                                                                     ZONENAMES     
##                                                                                                                                                                                                          :594029  
##                                                                                                                                                                                                          :205988  
##  GREATER RENO / CARSON CITY / M - GREATER RENO / CARSON CITY / M                                                                                                                                         :   639  
##  GREATER LAKE TAHOE AREA - GREATER LAKE TAHOE AREA                                                                                                                                                       :   592  
##  JEFFERSON - JEFFERSON                                                                                                                                                                                   :   303  
##  MADISON - MADISON                                                                                                                                                                                       :   302  
##  (Other)                                                                                                                                                                                                 :100444  
##     LATITUDE      LONGITUDE        LATITUDE_E     LONGITUDE_    
##  Min.   :   0   Min.   :-14451   Min.   :   0   Min.   :-14455  
##  1st Qu.:2802   1st Qu.:  7247   1st Qu.:   0   1st Qu.:     0  
##  Median :3540   Median :  8707   Median :   0   Median :     0  
##  Mean   :2875   Mean   :  6940   Mean   :1452   Mean   :  3509  
##  3rd Qu.:4019   3rd Qu.:  9605   3rd Qu.:3549   3rd Qu.:  8735  
##  Max.   :9706   Max.   : 17124   Max.   :9706   Max.   :106220  
##  NA's   :47                      NA's   :40                     
##                                            REMARKS           REFNUM      
##                                                :287433   Min.   :     1  
##                                                : 24013   1st Qu.:225575  
##  Trees down.\n                                 :  1110   Median :451149  
##  Several trees were blown down.\n              :   568   Mean   :451149  
##  Trees were downed.\n                          :   446   3rd Qu.:676723  
##  Large trees and power lines were blown down.\n:   432   Max.   :902297  
##  (Other)                                       :588295
# See number of NA for each variable
sapply(storm, function(x) sum(is.na(x)))
##    STATE__   BGN_DATE   BGN_TIME  TIME_ZONE     COUNTY COUNTYNAME 
##          0          0          0          0          0          0 
##      STATE     EVTYPE  BGN_RANGE    BGN_AZI BGN_LOCATI   END_DATE 
##          0          0          0          0          0          0 
##   END_TIME COUNTY_END COUNTYENDN  END_RANGE    END_AZI END_LOCATI 
##          0          0     902297          0          0          0 
##     LENGTH      WIDTH          F        MAG FATALITIES   INJURIES 
##          0          0     843563          0          0          0 
##    PROPDMG PROPDMGEXP    CROPDMG CROPDMGEXP        WFO STATEOFFIC 
##          0          0          0          0          0          0 
##  ZONENAMES   LATITUDE  LONGITUDE LATITUDE_E LONGITUDE_    REMARKS 
##          0         47          0         40          0          0 
##     REFNUM 
##          0

Variables with >80% NA are removed from the dataset. And removed NA rows.

# Remove variables with >80% NA
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
storm2 <- select(storm, -c(COUNTYENDN, F))

# Remove NA rows
storm2 <- na.omit(storm2)

# Variable class cleaning
library(lubridate)
## 
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
## 
##     date
storm2$BGN_DATE <- mdy_hms(storm2$BGN_DATE)
storm2$END_DATE <- mdy_hms(storm2$END_DATE)
storm2$STATE__ <- as.factor(storm2$STATE__)
storm2$COUNTY <- as.factor(storm2$COUNTY)
storm2$REFNUM <- as.factor(storm2$REFNUM)

# Check summary
summary(storm2)
##     STATE__          BGN_DATE                          BGN_TIME     
##  48     : 83728   Min.   :1950-01-03 00:00:00   12:00:00 AM: 10162  
##  20     : 53441   1st Qu.:1995-04-19 00:00:00   06:00:00 PM:  7350  
##  40     : 46802   Median :2002-03-17 00:00:00   04:00:00 PM:  7261  
##  29     : 35648   Mean   :1998-12-27 18:58:13   05:00:00 PM:  6891  
##  19     : 31069   3rd Qu.:2007-07-27 00:00:00   12:00:00 PM:  6701  
##  31     : 30271   Max.   :2011-11-30 00:00:00   03:00:00 PM:  6700  
##  (Other):621291                                 (Other)    :857185  
##    TIME_ZONE          COUNTY            COUNTYNAME         STATE       
##  CST    :547493   1      : 17810   JEFFERSON :  7840   TX     : 83728  
##  EST    :245558   3      : 16218   WASHINGTON:  7603   KS     : 53440  
##  MST    : 68390   19     : 14141   JACKSON   :  6660   OK     : 46802  
##  PST    : 28302   15     : 13858   FRANKLIN  :  6256   MO     : 35648  
##  AST    :  6360   5      : 13847   LINCOLN   :  5937   IA     : 31069  
##  HST    :  2563   17     : 13081   MADISON   :  5632   NE     : 30271  
##  (Other):  3584   (Other):813295   (Other)   :862322   (Other):621292  
##                EVTYPE         BGN_RANGE           BGN_AZI      
##  HAIL             :288661   Min.   :   0.000          :547332  
##  TSTM WIND        :219940   1st Qu.:   0.000   N      : 86737  
##  THUNDERSTORM WIND: 82563   Median :   0.000   W      : 38444  
##  TORNADO          : 60652   Mean   :   1.484   S      : 37558  
##  FLASH FLOOD      : 54262   3rd Qu.:   1.000   E      : 33172  
##  FLOOD            : 25326   Max.   :3749.000   NW     : 24038  
##  (Other)          :170846                      (Other):134969  
##          BGN_LOCATI        END_DATE                          END_TIME     
##               :287743   Min.   :1986-04-10 00:00:00              :238978  
##  COUNTYWIDE   : 19680   1st Qu.:2000-09-01 00:00:00   06:00:00 PM:  9802  
##  Countywide   :   993   Median :2005-04-30 00:00:00   05:00:00 PM:  8314  
##  SPRINGFIELD  :   843   Mean   :2004-09-26 01:24:09   04:00:00 PM:  8101  
##  SOUTH PORTION:   810   3rd Qu.:2008-08-10 00:00:00   12:00:00 PM:  7481  
##  NORTH PORTION:   784   Max.   :2011-11-30 00:00:00   11:59:00 PM:  7184  
##  (Other)      :591397   NA's   :243411                (Other)    :622390  
##    COUNTY_END   END_RANGE           END_AZI                 END_LOCATI    
##  Min.   :0    Min.   :  0.0000          :724830                  :499218  
##  1st Qu.:0    1st Qu.:  0.0000   N      : 28069   COUNTYWIDE     : 19731  
##  Median :0    Median :  0.0000   S      : 22510   SOUTH PORTION  :   833  
##  Mean   :0    Mean   :  0.9858   W      : 20114   NORTH PORTION  :   780  
##  3rd Qu.:0    3rd Qu.:  0.0000   E      : 20041   CENTRAL PORTION:   617  
##  Max.   :0    Max.   :925.0000   NE     : 14599   SPRINGFIELD    :   575  
##                                  (Other): 72087   (Other)        :380496  
##      LENGTH              WIDTH               MAG         
##  Min.   :   0.0000   Min.   :   0.000   Min.   :    0.0  
##  1st Qu.:   0.0000   1st Qu.:   0.000   1st Qu.:    0.0  
##  Median :   0.0000   Median :   0.000   Median :   50.0  
##  Mean   :   0.2301   Mean   :   7.503   Mean   :   46.9  
##  3rd Qu.:   0.0000   3rd Qu.:   0.000   3rd Qu.:   75.0  
##  Max.   :2315.0000   Max.   :4400.000   Max.   :22000.0  
##                                                          
##    FATALITIES          INJURIES            PROPDMG          PROPDMGEXP    
##  Min.   :  0.0000   Min.   :   0.0000   Min.   :   0.00          :465934  
##  1st Qu.:  0.0000   1st Qu.:   0.0000   1st Qu.:   0.00   K      :424618  
##  Median :  0.0000   Median :   0.0000   Median :   0.00   M      : 11330  
##  Mean   :  0.0168   Mean   :   0.1558   Mean   :  12.06   0      :   216  
##  3rd Qu.:  0.0000   3rd Qu.:   0.0000   3rd Qu.:   0.50   B      :    40  
##  Max.   :583.0000   Max.   :1700.0000   Max.   :5000.00   5      :    28  
##                                                           (Other):    84  
##     CROPDMG          CROPDMGEXP          WFO        
##  Min.   :  0.000          :618413          :142069  
##  1st Qu.:  0.000   K      :281785   OUN    : 17393  
##  Median :  0.000   M      :  1994   JAN    : 13889  
##  Mean   :  1.527   k      :    21   LWX    : 13174  
##  3rd Qu.:  0.000   0      :    19   PHI    : 12551  
##  Max.   :990.000   B      :     9   TSA    : 12483  
##                    (Other):     9   (Other):690691  
##                                STATEOFFIC    
##                                     :248769  
##  TEXAS, North                       : 12193  
##  ARKANSAS, Central and North Central: 11738  
##  IOWA, Central                      : 11345  
##  KANSAS, Southwest                  : 11212  
##  GEORGIA, North and Central         : 11120  
##  (Other)                            :595873  
##                                                                                                                                                                                                     ZONENAMES     
##                                                                                                                                                                                                          :594029  
##                                                                                                                                                                                                          :205941  
##  GREATER RENO / CARSON CITY / M - GREATER RENO / CARSON CITY / M                                                                                                                                         :   639  
##  GREATER LAKE TAHOE AREA - GREATER LAKE TAHOE AREA                                                                                                                                                       :   592  
##  JEFFERSON - JEFFERSON                                                                                                                                                                                   :   303  
##  MADISON - MADISON                                                                                                                                                                                       :   302  
##  (Other)                                                                                                                                                                                                 :100444  
##     LATITUDE      LONGITUDE        LATITUDE_E     LONGITUDE_    
##  Min.   :   0   Min.   :-14451   Min.   :   0   Min.   :-14455  
##  1st Qu.:2802   1st Qu.:  7247   1st Qu.:   0   1st Qu.:     0  
##  Median :3540   Median :  8707   Median :   0   Median :     0  
##  Mean   :2875   Mean   :  6939   Mean   :1452   Mean   :  3509  
##  3rd Qu.:4019   3rd Qu.:  9605   3rd Qu.:3549   3rd Qu.:  8735  
##  Max.   :9706   Max.   : 17124   Max.   :9706   Max.   :106220  
##                                                                 
##                                            REMARKS           REFNUM      
##                                                :287433   1      :     1  
##                                                : 24013   2      :     1  
##  Trees down.\n                                 :  1110   3      :     1  
##  Several trees were blown down.\n              :   568   4      :     1  
##  Trees were downed.\n                          :   446   5      :     1  
##  Large trees and power lines were blown down.\n:   432   6      :     1  
##  (Other)                                       :588248   (Other):902244
str(storm2)
## 'data.frame':    902250 obs. of  35 variables:
##  $ STATE__   : Factor w/ 70 levels "1","2","4","5",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ BGN_DATE  : POSIXct, format: "1950-04-18" "1950-04-18" ...
##  $ BGN_TIME  : Factor w/ 3608 levels "00:00:00 AM",..: 272 287 2705 1683 2584 3186 242 1683 3186 3186 ...
##  $ TIME_ZONE : Factor w/ 22 levels "ADT","AKS","AST",..: 7 7 7 7 7 7 7 7 7 7 ...
##  $ COUNTY    : Factor w/ 557 levels "0","1","2","3",..: 98 4 58 90 44 78 10 124 126 58 ...
##  $ COUNTYNAME: Factor w/ 29601 levels "","5NM E OF MACKINAC BRIDGE TO PRESQUE ISLE LT MI",..: 13513 1873 4598 10592 4372 10094 1973 23873 24418 4598 ...
##  $ STATE     : Factor w/ 72 levels "AK","AL","AM",..: 2 2 2 2 2 2 2 2 2 2 ...
##  $ EVTYPE    : Factor w/ 985 levels "   HIGH SURF ADVISORY",..: 834 834 834 834 834 834 834 834 834 834 ...
##  $ BGN_RANGE : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ BGN_AZI   : Factor w/ 35 levels "","  N"," NW",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ BGN_LOCATI: Factor w/ 54429 levels "","- 1 N Albion",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ END_DATE  : POSIXct, format: NA NA ...
##  $ END_TIME  : Factor w/ 3647 levels ""," 0900CST",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ COUNTY_END: num  0 0 0 0 0 0 0 0 0 0 ...
##  $ END_RANGE : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ END_AZI   : Factor w/ 24 levels "","E","ENE","ESE",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ END_LOCATI: Factor w/ 34506 levels "","- .5 NNW",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ LENGTH    : num  14 2 0.1 0 0 1.5 1.5 0 3.3 2.3 ...
##  $ WIDTH     : num  100 150 123 100 150 177 33 33 100 100 ...
##  $ MAG       : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ FATALITIES: num  0 0 0 0 0 0 0 0 1 0 ...
##  $ INJURIES  : num  15 0 2 2 2 6 1 0 14 0 ...
##  $ PROPDMG   : num  25 2.5 25 2.5 2.5 2.5 2.5 2.5 25 25 ...
##  $ PROPDMGEXP: Factor w/ 19 levels "","-","?","+",..: 17 17 17 17 17 17 17 17 17 17 ...
##  $ CROPDMG   : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ CROPDMGEXP: Factor w/ 9 levels "","?","0","2",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ WFO       : Factor w/ 542 levels ""," CI","$AC",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ STATEOFFIC: Factor w/ 250 levels "","ALABAMA, Central",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ ZONENAMES : Factor w/ 25112 levels "","                                                                                                               "| __truncated__,..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ LATITUDE  : num  3040 3042 3340 3458 3412 ...
##  $ LONGITUDE : num  8812 8755 8742 8626 8642 ...
##  $ LATITUDE_E: num  3051 0 0 0 0 ...
##  $ LONGITUDE_: num  8806 0 0 0 0 ...
##  $ REMARKS   : Factor w/ 436781 levels "","-2 at Deer Park\n",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ REFNUM    : Factor w/ 902250 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...
##  - attr(*, "na.action")=Class 'omit'  Named int [1:47] 647217 647219 647220 647221 690294 690295 690297 690298 690303 690304 ...
##   .. ..- attr(*, "names")= chr [1:47] "647217" "647219" "647220" "647221" ...

Results

Question 1: Across the United States, which types of events (as indicated in the EVTYPE variable) are most harmful with respect to population health?

library(ggplot2)

# Plot Number of Fatalities by EVTYPE
table1 <- summarise(group_by(storm2,EVTYPE),Total_death=sum(FATALITIES))
table1 <- arrange(table1,desc(Total_death))[1:10,]
plot1 <- ggplot(table1, aes(x=reorder(EVTYPE,Total_death), y=Total_death, fill=Total_death)) + 
  geom_bar(stat="identity") + 
  scale_fill_gradient2(low='red', mid='snow3', high='red', space='Lab') +
  labs(title="Top 10 Event by Number of Fatalities", y="Number of Fatalities", x="Event") +
  coord_flip()
plot1

# Plot Number of Injuries by EVTYPE
table2 <- summarise(group_by(storm2,EVTYPE),Total_injuries=sum(INJURIES))
table2 <- arrange(table2,desc(Total_injuries))[1:10,]
plot2 <- ggplot(table2,aes(x=reorder(EVTYPE,Total_injuries), y=Total_injuries, fill=Total_injuries)) + 
  geom_bar(stat="identity") +  
  scale_fill_gradient2(low='red', mid='snow3', high='purple', space='Lab') +
  labs(title="Top 10 Event by Number of Injuries", y="Number of Injuries", x="Event") +
  coord_flip()
plot2

# Show both death & injuries tables
library(formattable)
## Warning: package 'formattable' was built under R version 3.4.3
table1 <- mutate(table1, Percentage=percent(Total_death/sum(Total_death)))
table1
## # A tibble: 10 x 3
##            EVTYPE Total_death        Percentage
##            <fctr>       <dbl> <S3: formattable>
##  1        TORNADO        5633            46.63%
##  2 EXCESSIVE HEAT        1903            15.75%
##  3    FLASH FLOOD         978             8.10%
##  4           HEAT         937             7.76%
##  5      LIGHTNING         816             6.75%
##  6      TSTM WIND         504             4.17%
##  7          FLOOD         470             3.89%
##  8    RIP CURRENT         368             3.05%
##  9      HIGH WIND         248             2.05%
## 10      AVALANCHE         224             1.85%
table2 <- mutate(table2, Percentage=percent(Total_injuries/sum(Total_injuries)))
table2
## # A tibble: 10 x 3
##               EVTYPE Total_injuries        Percentage
##               <fctr>          <dbl> <S3: formattable>
##  1           TORNADO          91346            72.76%
##  2         TSTM WIND           6957             5.54%
##  3             FLOOD           6789             5.41%
##  4    EXCESSIVE HEAT           6525             5.20%
##  5         LIGHTNING           5230             4.17%
##  6              HEAT           2100             1.67%
##  7         ICE STORM           1975             1.57%
##  8       FLASH FLOOD           1777             1.42%
##  9 THUNDERSTORM WIND           1488             1.19%
## 10              HAIL           1361             1.08%

Comment: Based on the data above, we can see Tornado is most harmful with respect to population health. Tornado caused the highest total death (46.63%) and highest injuries (72.76%).

Question 2: Across the United States, which types of events have the greatest economic consequences?

# Plot Number of Property Damage by EVTYPE
table3 <- summarise(group_by(storm2, EVTYPE), Total_PropDmg=sum(PROPDMG))
table3 <- arrange(table3,desc(Total_PropDmg))[1:10,]

plot3 <- ggplot(table3, aes(x=reorder(EVTYPE,Total_PropDmg), y=Total_PropDmg, fill=Total_PropDmg)) + 
  geom_bar(stat="identity") + 
  scale_fill_gradient2(low='red', mid='snow3', high='dark green', space='Lab') + 
  labs(title="Top 10 Event by Number of Property Damage", y="Number of Property Damage", x="Event") +
  coord_flip()
plot3

# Show property damage table
table3 <- mutate(table3, Percentage=percent(Total_PropDmg/sum(Total_PropDmg)))
table3
## # A tibble: 10 x 3
##                EVTYPE Total_PropDmg        Percentage
##                <fctr>         <dbl> <S3: formattable>
##  1            TORNADO     3212258.2            32.31%
##  2        FLASH FLOOD     1419874.6            14.28%
##  3          TSTM WIND     1335965.6            13.44%
##  4              FLOOD      899938.5             9.05%
##  5  THUNDERSTORM WIND      876844.2             8.82%
##  6               HAIL      688693.4             6.93%
##  7          LIGHTNING      603231.8             6.07%
##  8 THUNDERSTORM WINDS      446293.2             4.49%
##  9          HIGH WIND      324731.6             3.27%
## 10       WINTER STORM      132720.6             1.34%

Comment: The Top 10 EVTYPE by Number of Property Damage shows that Tornado is the worst type of event which accounted for 32.31% of total Property Damaged.