Analysis of the Impact of Sever Weather Events on Population Health and Economy across the United States

Synopsis

In this report we aim to investigate the impact of sever weather events on population health and economy across the United States between the years 1950 and 2011. Our goal is to identify the most harmful types of events with respect to population health, and the types of events that have the greatest economic consequences. To achive this goal, we used the U.S. National Oceanic and Atmospheric Administration's (NOAA) storm database.

Our findings show that convection, flood, and winter related weather events are respectively the most harmful types of events. On the other hand, flood, tropical cyclones, and convection related weather events have respectively the greatest economic consequences. Marine related events are the least harmful with lowest economic consequences.

Data Processing

This section describes how the data were loaded into R and processed for analysis.

1 - Downloading the Data:

# To avoid the Error message: 'unsupported URL scheme message' generated by
# Knitr when downloading from https
setInternet2(TRUE)

# Data file url
url <- "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2"

# Create the directory 'data' if it doesn't exist
if (!file.exists("data")) {
    dir.create("data")

}
# Download the data file
download.file(url, "data/stormData.csv.bz2")

# Record the date the file was downloaded
date_downloaded <- date()
date_downloaded
## [1] "Sun May 25 17:07:06 2014"

2 - Reading the Data:

# Opening a connection with the compressed data file
conn <- bzfile("data/stormData.csv.bz2", open = "r")
# Reading the data from the connection
data <- read.csv(conn, stringsAsFactors = FALSE, strip.white = TRUE)
# Closing the connection
close(conn)

3 - Exploring the Data:

Looking at a summary of the data using str and summary functions:

str(data)
## 'data.frame':    902297 obs. of  37 variables:
##  $ STATE__   : num  1 1 1 1 1 1 1 1 1 1 ...
##  $ BGN_DATE  : chr  "4/18/1950 0:00:00" "4/18/1950 0:00:00" "2/20/1951 0:00:00" "6/8/1951 0:00:00" ...
##  $ BGN_TIME  : chr  "0130" "0145" "1600" "0900" ...
##  $ TIME_ZONE : chr  "CST" "CST" "CST" "CST" ...
##  $ COUNTY    : num  97 3 57 89 43 77 9 123 125 57 ...
##  $ COUNTYNAME: chr  "MOBILE" "BALDWIN" "FAYETTE" "MADISON" ...
##  $ STATE     : chr  "AL" "AL" "AL" "AL" ...
##  $ EVTYPE    : chr  "TORNADO" "TORNADO" "TORNADO" "TORNADO" ...
##  $ BGN_RANGE : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ BGN_AZI   : chr  "" "" "" "" ...
##  $ BGN_LOCATI: chr  "" "" "" "" ...
##  $ END_DATE  : chr  "" "" "" "" ...
##  $ END_TIME  : chr  "" "" "" "" ...
##  $ COUNTY_END: num  0 0 0 0 0 0 0 0 0 0 ...
##  $ COUNTYENDN: logi  NA NA NA NA NA NA ...
##  $ END_RANGE : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ END_AZI   : chr  "" "" "" "" ...
##  $ END_LOCATI: chr  "" "" "" "" ...
##  $ 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 ...
##  $ F         : int  3 2 2 2 2 2 2 1 3 3 ...
##  $ 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: chr  "K" "K" "K" "K" ...
##  $ CROPDMG   : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ CROPDMGEXP: chr  "" "" "" "" ...
##  $ WFO       : chr  "" "" "" "" ...
##  $ STATEOFFIC: chr  "" "" "" "" ...
##  $ ZONENAMES : chr  "" "" "" "" ...
##  $ 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   : chr  "" "" "" "" ...
##  $ REFNUM    : num  1 2 3 4 5 6 7 8 9 10 ...
summary(data)
##     STATE__       BGN_DATE           BGN_TIME          TIME_ZONE        
##  Min.   : 1.0   Length:902297      Length:902297      Length:902297     
##  1st Qu.:19.0   Class :character   Class :character   Class :character  
##  Median :30.0   Mode  :character   Mode  :character   Mode  :character  
##  Mean   :31.2                                                           
##  3rd Qu.:45.0                                                           
##  Max.   :95.0                                                           
##                                                                         
##      COUNTY     COUNTYNAME           STATE              EVTYPE         
##  Min.   :  0   Length:902297      Length:902297      Length:902297     
##  1st Qu.: 31   Class :character   Class :character   Class :character  
##  Median : 75   Mode  :character   Mode  :character   Mode  :character  
##  Mean   :101                                                           
##  3rd Qu.:131                                                           
##  Max.   :873                                                           
##                                                                        
##    BGN_RANGE      BGN_AZI           BGN_LOCATI          END_DATE        
##  Min.   :   0   Length:902297      Length:902297      Length:902297     
##  1st Qu.:   0   Class :character   Class :character   Class :character  
##  Median :   0   Mode  :character   Mode  :character   Mode  :character  
##  Mean   :   1                                                           
##  3rd Qu.:   1                                                           
##  Max.   :3749                                                           
##                                                                         
##    END_TIME           COUNTY_END COUNTYENDN       END_RANGE  
##  Length:902297      Min.   :0    Mode:logical   Min.   :  0  
##  Class :character   1st Qu.:0    NA's:902297    1st Qu.:  0  
##  Mode  :character   Median :0                   Median :  0  
##                     Mean   :0                   Mean   :  1  
##                     3rd Qu.:0                   3rd Qu.:  0  
##                     Max.   :0                   Max.   :925  
##                                                              
##    END_AZI           END_LOCATI            LENGTH           WIDTH     
##  Length:902297      Length:902297      Min.   :   0.0   Min.   :   0  
##  Class :character   Class :character   1st Qu.:   0.0   1st Qu.:   0  
##  Mode  :character   Mode  :character   Median :   0.0   Median :   0  
##                                        Mean   :   0.2   Mean   :   8  
##                                        3rd Qu.:   0.0   3rd Qu.:   0  
##                                        Max.   :2315.0   Max.   :4400  
##                                                                       
##        F               MAG          FATALITIES     INJURIES     
##  Min.   :0        Min.   :    0   Min.   :  0   Min.   :   0.0  
##  1st Qu.:0        1st Qu.:    0   1st Qu.:  0   1st Qu.:   0.0  
##  Median :1        Median :   50   Median :  0   Median :   0.0  
##  Mean   :1        Mean   :   47   Mean   :  0   Mean   :   0.2  
##  3rd Qu.:1        3rd Qu.:   75   3rd Qu.:  0   3rd Qu.:   0.0  
##  Max.   :5        Max.   :22000   Max.   :583   Max.   :1700.0  
##  NA's   :843563                                                 
##     PROPDMG      PROPDMGEXP           CROPDMG       CROPDMGEXP       
##  Min.   :   0   Length:902297      Min.   :  0.0   Length:902297     
##  1st Qu.:   0   Class :character   1st Qu.:  0.0   Class :character  
##  Median :   0   Mode  :character   Median :  0.0   Mode  :character  
##  Mean   :  12                      Mean   :  1.5                     
##  3rd Qu.:   0                      3rd Qu.:  0.0                     
##  Max.   :5000                      Max.   :990.0                     
##                                                                      
##      WFO             STATEOFFIC         ZONENAMES            LATITUDE   
##  Length:902297      Length:902297      Length:902297      Min.   :   0  
##  Class :character   Class :character   Class :character   1st Qu.:2802  
##  Mode  :character   Mode  :character   Mode  :character   Median :3540  
##                                                           Mean   :2875  
##                                                           3rd Qu.:4019  
##                                                           Max.   :9706  
##                                                           NA's   :47    
##    LONGITUDE        LATITUDE_E     LONGITUDE_       REMARKS         
##  Min.   :-14451   Min.   :   0   Min.   :-14455   Length:902297     
##  1st Qu.:  7247   1st Qu.:   0   1st Qu.:     0   Class :character  
##  Median :  8707   Median :   0   Median :     0   Mode  :character  
##  Mean   :  6940   Mean   :1452   Mean   :  3509                     
##  3rd Qu.:  9605   3rd Qu.:3549   3rd Qu.:  8735                     
##  Max.   : 17124   Max.   :9706   Max.   :106220                     
##                   NA's   :40                                        
##      REFNUM      
##  Min.   :     1  
##  1st Qu.:225575  
##  Median :451149  
##  Mean   :451149  
##  3rd Qu.:676723  
##  Max.   :902297  
## 

4 - Selecting the Data of Interest:

We are interested in the weather events that have either fatalities, injuries, crop damage or property damage

# Number of observations in the whole data
nrow(data)
## [1] 902297
# Selecting data with fatalities, injuries, crop damage orproperty damage
reduced_data <- data[data$FATALITIES > 0 | data$INJURIES > 0 | data$PROPDMG > 
    0 | data$CROPDMG > 0, ]
# Number of observations in the new data set
nrow(reduced_data)
## [1] 254633

As shown above, we reduced the size of the data from 902297 to 254633 observations.

5 - Exploaring the Types of Weather Events in the Data::

# The number of unique weather events in the data (Case-sensitive)
length(unique(reduced_data$EVTYPE))
## [1] 488
# The number of unique weather events in the data (all lower case)
length(unique(tolower(reduced_data$EVTYPE)))
## [1] 447
# Converting the raw types of events to lower case
reduced_data$EVTYPE <- tolower(reduced_data$EVTYPE)
# Creating a data frame with the frequency of raw events
raw_events <- as.data.frame(table(reduced_data$EVTYPE))
# Adding names to the data frame
names(raw_events) <- c("event", "frequency")
# Ordering the data frame based on decreasing frequency
raw_events <- raw_events[order(raw_events$frequency, decreasing = TRUE), ]
# Looking at the 40 top raw events in the data
head(raw_events, n = 40)
##                    event frequency
## 386            tstm wind     63235
## 329    thunderstorm wind     43655
## 371              tornado     39944
## 116                 hail     26130
## 65           flash flood     20967
## 233            lightning     13293
## 346   thunderstorm winds     12086
## 78                 flood     10175
## 179            high wind      5522
## 319          strong wind      3372
## 441         winter storm      1508
## 151           heavy snow      1342
## 140           heavy rain      1105
## 433             wildfire       857
## 216            ice storm       708
## 419 urban/sml stream fld       702
## 54        excessive heat       698
## 187           high winds       657
## 400       tstm wind/hail       441
## 381       tropical storm       416
## 444       winter weather       407
## 276          rip current       400
## 431     wild/forest fire       388
## 74        flash flooding       302
## 82     flood/flash flood       279
## 11             avalanche       268
## 43               drought       266
## 14              blizzard       253
## 277         rip currents       241
## 133                 heat       215
## 59          extreme cold       199
## 220     lake-effect snow       194
## 224            landslide       193
## 317          storm surge       177
## 22         coastal flood       168
## 230           light snow       141
## 413          urban flood       139
## 446   winter weather/mix       139
## 174            high surf       136
## 194            hurricane       129

6 - Events Types Transformation::

As shown in the previous section, the raw types of events (in reduced_data$EVTYPE) have many malformed values and overlapping types. In addition, the number of unique values is big for the purpose of this analysis. Therefore, we decided to merge the 447 types of events into 7 types of events. The new types of events are: convection, extreme temperatures, flood, marine, tropical cyclones, winter, and other.

# Add a new column to the reduced data frame to store the merged type of
# events, and assign the value 'other'
reduced_data$merged_events <- "other"

# Creating sub-events for to be merged
convection <- "lightning|tornado|thunderstorm wind|tstm wind|hail|high wind|strong wind|strong winds|thunderstorm winds|thunderstorm windss|high winds|wind|winds|gusty wind|tstm wind/hail|tstm wind (g40)|thunderstorm winds lightning|tornado f0|tornado f1|thunderstorm wind/ trees|hail 275|hailstorm|thunderstorm  winds|thunderstorms wind|thundertorm winds|tstm wind|hail/winds|hail/wind|hail 175"

extreme_temperatures <- "heat|cold|extreme cold|excessive heat|warm weather|freeze|frost/freeze|cold weather|low temperature|extreme cold/wind chill"

flood <- "flash flood|flood|flash flooding|flood/flash flood|coastal flood|urban flood|lakeshore flood|flash flooding/flood|urban/small stream flood|heavy rains/flooding|flash floods|flash flood/flood|river flooding|flooding|coastal flooding|urban flooding|river flood|urban/sml stream fld"

marine <- "rip current|storm surge/tide|heavy surf/high surf|marine strong wind|marine tstm wind|marine thunderstorm wind|tsunami|coastal storm"

tropical_cyclones <- "hurricane|tropical storm|hurricane/typhoon|hurricane erin|hurricane opal"

winter <- "winter storm|ice storm|heavy snow|heavy rain|winter weather|avalanche|lake-effect snow|storm surge|light snow|winter weather/mix|lake effect snow|freezing rain/snow|damaging freeze|rain|freezing drizzle|snow freezing rain|snow squalls|heavy snow-squalls|heavy snow-squalls|heavy rains|light freezing rain|glaze|excessive snow|freezing rain|snow|frost/freeze"

# Merging the raw types of events to the 7 new types
reduced_data$merged_events[grepl(convection, reduced_data$EVTYPE)] <- "convection"
reduced_data$merged_events[grepl(extreme_temperatures, reduced_data$EVTYPE)] <- "extreme temperatures"
reduced_data$merged_events[grepl(flood, reduced_data$EVTYPE)] <- "flood"
reduced_data$merged_events[grepl(marine, reduced_data$EVTYPE)] <- "marine"
reduced_data$merged_events[grepl(tropical_cyclones, reduced_data$EVTYPE)] <- "tropical cyclones"
reduced_data$merged_events[grepl(winter, reduced_data$EVTYPE)] <- "winter"
# Converting the new types of events to a factor
reduced_data$merged_events <- as.factor(reduced_data$merged_events)

Looking at the new merged types of events:

new_events <- as.data.frame(table(reduced_data$merged_events))
# Adding names to the data frame
names(new_events) <- c("event", "frequency")
# Ordering the data frame based on decreasing frequency
new_events <- new_events[order(new_events$frequency, decreasing = TRUE), ]
# Looking at the new events
new_events
##                  event frequency
## 1           convection    208900
## 3                flood     33163
## 7               winter      6544
## 5                other      3005
## 2 extreme temperatures      1477
## 4               marine       899
## 6    tropical cyclones       645

7 - Exploaring the columns related to property and crop damages (PROPDMG, PROPDMGEXP, CROPDMG, CROPDMGEXP):

Looking at summary for PROPDMG and CROPDMG:

# summary forr PROPDMG
summary(reduced_data$PROPDMG)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##       0       2       5      43      25    5000
# summary for CROPDMG
summary(reduced_data$CROPDMG)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##     0.0     0.0     0.0     5.4     0.0   990.0

Looking at the unique values for PROPDMGEXP and CROPDMGEXP:

# Uniques valuse for PROPDMGEXP
unique(reduced_data$PROPDMGEXP)
##  [1] "K" "M" ""  "B" "m" "+" "0" "5" "6" "4" "h" "2" "7" "3" "H" "-"
# Uniques valuse for CROPDMGEXP
unique(reduced_data$CROPDMGEXP)
## [1] ""  "M" "K" "m" "B" "?" "0" "k"

8 - Transformation for PROPDMGEXP and CROPDMGEXP:

As shown in section 6, we need to transform the PROPDMGEXP and CROPDMGEXP (to reflect the actual numerical values) in order to use them in our analysis. For this analysis, we consider four numarical values(hundred (h), thousands (k), millions (m), billions (b) ). The remaning values (e.g. “+” “0” “5”, etc.) were ignored due to their ambiguity. Then we create new columns to store the property and crop numerical values of damage.

# Convertin to lower case
reduced_data$PROPDMGEXP <- tolower(reduced_data$PROPDMGEXP)
reduced_data$CROPDMGEXP <- tolower(reduced_data$CROPDMGEXP)

# Set of valid values
valid_values <- c("h", "k", "m", "b")

# Subsetting the data to include only observations with valid values
reduced_data <- reduced_data[reduced_data$PROPDMGEXP %in% valid_values, ]
reduced_data <- reduced_data[reduced_data$CROPDMGEXP %in% valid_values, ]

# Subsetting the data to exclude observations with zero value in PROPDMG or
# CROPDMG
reduced_data <- reduced_data[reduced_data$CROPDMG != 0 | reduced_data$PROPDMG != 
    0, ]

# Relacing the valid values by their numerical values
reduced_data$PROPDMGEXP <- gsub("b", 1e+09, reduced_data$PROPDMGEXP)
reduced_data$PROPDMGEXP <- gsub("m", 1e+06, reduced_data$PROPDMGEXP)
reduced_data$PROPDMGEXP <- gsub("k", 1000, reduced_data$PROPDMGEXP)
reduced_data$PROPDMGEXP <- gsub("h", 100, reduced_data$PROPDMGEXP)
reduced_data$CROPDMGEXP <- gsub("b", 1e+09, reduced_data$CROPDMGEXP)
reduced_data$CROPDMGEXP <- gsub("m", 1e+06, reduced_data$CROPDMGEXP)
reduced_data$CROPDMGEXP <- gsub("k", 1000, reduced_data$CROPDMGEXP)
reduced_data$CROPDMGEXP <- gsub("h", 100, reduced_data$CROPDMGEXP)

# Converting to numarical values
reduced_data$PROPDMGEXP <- as.numeric(reduced_data$PROPDMGEXP)
reduced_data$CROPDMGEXP <- as.numeric(reduced_data$CROPDMGEXP)

# Creating new columns to store property and crop numerical values of
# damage.
reduced_data$prob_dmg <- reduced_data$PROPDMG * reduced_data$PROPDMGEXP
# summary of property damage
summary(reduced_data$prob_dmg)
##     Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
## 0.00e+00 3.00e+03 1.00e+04 2.41e+06 3.50e+04 1.15e+11
reduced_data$crop_dmg <- reduced_data$CROPDMG * reduced_data$CROPDMGEXP
# summary of crop damage
summary(reduced_data$crop_dmg)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## 0.0e+00 0.0e+00 0.0e+00 3.2e+05 0.0e+00 5.0e+09
# Total damage
reduced_data$total_dmg <- reduced_data$prob_dmg + reduced_data$prob_dmg
# summary of total damage
summary(reduced_data$total_dmg)
##     Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
## 0.00e+00 6.00e+03 2.00e+04 4.82e+06 7.00e+04 2.30e+11

9 - Exploaring the 'FATALITIES' and 'INJURIES' columns:

Looking at summary for FATALITIES and INJURIES:

# summary for FATALITIES
summary(reduced_data$FATALITIES)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    0.00    0.00    0.00    0.02    0.00  158.00
# summary for INJURIES
summary(reduced_data$INJURIES)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##     0.0     0.0     0.0     0.3     0.0  1570.0

Therefore, no transormation is required for these columns.

Results

This section presents the results of our analysis to answer the two main questions.

1 - The Most Harmful Types of Events with Respect to Population Health (across the United States):

Aggregating injuries and fatalities over event types

# Aggregation injuries per event
injuries_per_event <- aggregate(INJURIES ~ merged_events, reduced_data, sum)
# Ordering injuries per event
injuries_per_event <- injuries_per_event[order(injuries_per_event$INJURIES, 
    decreasing = TRUE), ]
injuries_per_event
##          merged_events INJURIES
## 1           convection    13390
## 3                flood     7104
## 7               winter     2013
## 6    tropical cyclones     1296
## 5                other     1005
## 2 extreme temperatures      519
## 4               marine      137

# Aggregation fatalities per event
fatalities_per_event <- aggregate(FATALITIES ~ merged_events, reduced_data, 
    sum)
# Ordering fatalities per event
fatalities_per_event <- fatalities_per_event[order(fatalities_per_event$FATALITIES, 
    decreasing = TRUE), ]
fatalities_per_event
##          merged_events FATALITIES
## 1           convection       1186
## 3                flood        516
## 6    tropical cyclones        100
## 5                other         92
## 2 extreme temperatures         76
## 7               winter         72
## 4               marine         39

# Aggregation total health impact (injuries + fatalities) per event
total_health_per_event <- aggregate((INJURIES + FATALITIES) ~ merged_events, 
    reduced_data, sum)
# Ordering total health impact per event
names(total_health_per_event) <- c("merged_events", "INJURIES_plus_FATALITIES")
total_health_per_event <- total_health_per_event[order(total_health_per_event$INJURIES_plus_FATALITIES, 
    decreasing = TRUE), ]
total_health_per_event
##          merged_events INJURIES_plus_FATALITIES
## 1           convection                    14576
## 3                flood                     7620
## 7               winter                     2085
## 6    tropical cyclones                     1396
## 5                other                     1097
## 2 extreme temperatures                      595
## 4               marine                      176

# Adding a new column to be used for figures
injuries_per_event$health_type <- "INJURIES"
fatalities_per_event$health_type <- "FATALITIES"
names(injuries_per_event) <- c("merged_events", "count", "health_type")
names(fatalities_per_event) <- c("merged_events", "count", "health_type")

# Combining both data frames
health_impact_per_event <- rbind(injuries_per_event, fatalities_per_event)

# Loading ggplo2 package
library(ggplot2)
# Ploting the property and crop damage per event type
qplot(as.factor(merged_events), count, data = health_impact_per_event, geom = "bar", 
    stat = "identity", position = "dodge", fill = health_type, xlab = "Type of Event", 
    ylab = "Count of Casualties", main = "Impact of Sever Weather Events on Population Health in US from 1950 to 2011")

plot of chunk unnamed-chunk-12

As shown from the tables and figure, the convection related weather events are the most harmful types of events with respect to population health. Flood and winter related events come in the second and third place respictively. Marine related events are the least harmful types of events with respect to population health.

2 - The Types of Events which Have the Greatest Economic Consequences (across the United States):

Aggregating Property and Crop Damage over Event Eypes

# Property damage per event type
prop_damage_per_event <- aggregate(prob_dmg ~ merged_events, reduced_data, sum)
# Ordering the property damage
prop_damage_per_event <- prop_damage_per_event[order(prop_damage_per_event$prob_dmg, 
    decreasing = TRUE), ]
prop_damage_per_event
##          merged_events  prob_dmg
## 3                flood 1.460e+11
## 6    tropical cyclones 4.004e+10
## 1           convection 3.306e+10
## 7               winter 7.225e+09
## 5                other 4.147e+09
## 4               marine 1.449e+08
## 2 extreme temperatures 1.255e+08

# Crop damage per event type
crop_damage_per_event <- aggregate(crop_dmg ~ merged_events, reduced_data, sum)
# Ordering the crop damage
crop_damage_per_event <- crop_damage_per_event[order(crop_damage_per_event$crop_dmg, 
    decreasing = TRUE), ]
crop_damage_per_event
##          merged_events  crop_dmg
## 3                flood 1.174e+10
## 7               winter 6.258e+09
## 6    tropical cyclones 5.801e+09
## 1           convection 4.260e+09
## 5                other 2.091e+09
## 2 extreme temperatures 5.037e+08
## 4               marine 7.000e+04

# Total (property + crop) damage per event type
total_damage_per_event <- aggregate((prob_dmg + crop_dmg) ~ merged_events, reduced_data, 
    sum)
names(total_damage_per_event) <- c("merged_events", "total_dmg")
# Ordering the crop damage
total_damage_per_event <- total_damage_per_event[order(total_damage_per_event$total_dmg, 
    decreasing = TRUE), ]
total_damage_per_event
##          merged_events total_dmg
## 3                flood 1.578e+11
## 6    tropical cyclones 4.584e+10
## 1           convection 3.732e+10
## 7               winter 1.348e+10
## 5                other 6.238e+09
## 2 extreme temperatures 6.292e+08
## 4               marine 1.450e+08

# Adding a new column to be used for figures
prop_damage_per_event$dmg_type <- "PROPDMG"
crop_damage_per_event$dmg_type <- "CROPDMG"
names(prop_damage_per_event) <- c("merged_events", "dmg_value", "dmg_type")
names(crop_damage_per_event) <- c("merged_events", "dmg_value", "dmg_type")

# Combining both data frames
damage_per_event <- rbind(prop_damage_per_event, crop_damage_per_event)

# Ploting the property and crop damage per event type
qplot(as.factor(merged_events), dmg_value/1e+09, data = damage_per_event, geom = "bar", 
    stat = "identity", position = "dodge", fill = dmg_type, xlab = "Type of Event", 
    ylab = "Damage (in Billions of Dollars)", main = "Economic Consequences (property and crop damage) of Sever Weather Events in US from 1950 to 2011")

plot of chunk unnamed-chunk-13

As shown in the figures, the flood related events have the greatest economic consequences. The tropical cyclones and convection come in the second and third places respectively. Marine related weather events have the lowest economic consequences.

# Ploting the total damage per event type
qplot(as.factor(merged_events), total_dmg/1e+09, data = total_damage_per_event, 
    geom = "bar", stat = "identity", position = "stack", fill = merged_events, 
    xlab = "Type of Event", ylab = "Damage (in Billions of Dollars)", main = "Total Economic Consequences of Sever Weather Events in US from 1950 to 2011")

plot of chunk unnamed-chunk-14