library(knitr)
opts_chunk$set(echo = TRUE, results = TRUE, cache = TRUE)
This project analyses the detrimental effects of severe weather conditions.Severe weather events in form of floods and tornadoes amongst other result in public health issues and major economic loss.
U.S. National Oceanic and Atmospheric Administration (NOAA) maintains database of severe weather events in the U.S. This database documents characteristic storms and adverse weather conditions including the date and location of occurrence, levels of fatalities, injuries and property loss.
The aim of this project is to explore the NOAA database from year 1950 till November 2011 and determine which types of severe weather conditions that have the most detrimental effects on:
# Set working directory
# Download file
setwd("C://Users//Olusola//Desktop//RR_WK4")
stormDataUrl <- "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2"
stormDatabzFile <- "StormData.csv.bz2"
if (!file.exists(stormDatabzFile)) {
download.file(stormDataUrl, stormDatabzFile, mode = "wb")
}
# Unzip downloaded file
# install.packages("R.utils") then load package
library(R.utils)
stormData <- "stormData.csv"
if(!file.exists(stormData)) {
bunzip2(stormDatabzFile, stormData, remove = FALSE, skip = TRUE)
}
Storm Data Documentation
National Climatic Data Center Storm Events FAQ
# Read data into a variable and observe data
storms <- read.csv(stormData, head = TRUE, sep = ",")
# Display storms as data table instead of data frame
library(data.table)
storms2 <- as.data.table(storms)
str(storms2)
## Classes 'data.table' and 'data.frame': 902297 obs. of 37 variables:
## $ STATE__ : num 1 1 1 1 1 1 1 1 1 1 ...
## $ BGN_DATE : Factor w/ 16335 levels "1/1/1966 0:00:00",..: 6523 6523 4242 11116 2224 2224 2260 383 3980 3980 ...
## $ 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 : num 97 3 57 89 43 77 9 123 125 57 ...
## $ 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 : Factor w/ 6663 levels "","1/1/1993 0:00:00",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ 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 ...
## $ COUNTYENDN: logi NA NA NA NA NA NA ...
## $ 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 ...
## $ 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: 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/ 436774 levels "","-2 at Deer Park\n",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ REFNUM : num 1 2 3 4 5 6 7 8 9 10 ...
## - attr(*, ".internal.selfref")=<externalptr>
summary(storms2)
## 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 : 569 Mean :451149
## Trees were downed.\n : 446 3rd Qu.:676723
## Large trees and power lines were blown down.\n: 432 Max. :902297
## (Other) :588294
head(storms2)
## STATE__ BGN_DATE BGN_TIME TIME_ZONE COUNTY COUNTYNAME STATE
## 1: 1 4/18/1950 0:00:00 0130 CST 97 MOBILE AL
## 2: 1 4/18/1950 0:00:00 0145 CST 3 BALDWIN AL
## 3: 1 2/20/1951 0:00:00 1600 CST 57 FAYETTE AL
## 4: 1 6/8/1951 0:00:00 0900 CST 89 MADISON AL
## 5: 1 11/15/1951 0:00:00 1500 CST 43 CULLMAN AL
## 6: 1 11/15/1951 0:00:00 2000 CST 77 LAUDERDALE AL
## EVTYPE BGN_RANGE BGN_AZI BGN_LOCATI END_DATE END_TIME COUNTY_END
## 1: TORNADO 0 0
## 2: TORNADO 0 0
## 3: TORNADO 0 0
## 4: TORNADO 0 0
## 5: TORNADO 0 0
## 6: TORNADO 0 0
## COUNTYENDN END_RANGE END_AZI END_LOCATI LENGTH WIDTH F MAG FATALITIES
## 1: NA 0 14.0 100 3 0 0
## 2: NA 0 2.0 150 2 0 0
## 3: NA 0 0.1 123 2 0 0
## 4: NA 0 0.0 100 2 0 0
## 5: NA 0 0.0 150 2 0 0
## 6: NA 0 1.5 177 2 0 0
## INJURIES PROPDMG PROPDMGEXP CROPDMG CROPDMGEXP WFO STATEOFFIC ZONENAMES
## 1: 15 25.0 K 0
## 2: 0 2.5 K 0
## 3: 2 25.0 K 0
## 4: 2 2.5 K 0
## 5: 2 2.5 K 0
## 6: 6 2.5 K 0
## LATITUDE LONGITUDE LATITUDE_E LONGITUDE_ REMARKS REFNUM
## 1: 3040 8812 3051 8806 1
## 2: 3042 8755 0 0 2
## 3: 3340 8742 0 0 3
## 4: 3458 8626 0 0 4
## 5: 3412 8642 0 0 5
## 6: 3450 8748 0 0 6
# View columns names i.e. the variables using colnames() or names()
colnames(storms2)
## [1] "STATE__" "BGN_DATE" "BGN_TIME" "TIME_ZONE" "COUNTY"
## [6] "COUNTYNAME" "STATE" "EVTYPE" "BGN_RANGE" "BGN_AZI"
## [11] "BGN_LOCATI" "END_DATE" "END_TIME" "COUNTY_END" "COUNTYENDN"
## [16] "END_RANGE" "END_AZI" "END_LOCATI" "LENGTH" "WIDTH"
## [21] "F" "MAG" "FATALITIES" "INJURIES" "PROPDMG"
## [26] "PROPDMGEXP" "CROPDMG" "CROPDMGEXP" "WFO" "STATEOFFIC"
## [31] "ZONENAMES" "LATITUDE" "LONGITUDE" "LATITUDE_E" "LONGITUDE_"
## [36] "REMARKS" "REFNUM"
Now separate the required columns from storm data
required_storms <- storms2[, c("EVTYPE", "FATALITIES", "INJURIES", "PROPDMG", "PROPDMGEXP", "CROPDMG", "CROPDMGEXP")]
# View required_storms
head(required_storms)
## EVTYPE FATALITIES INJURIES PROPDMG PROPDMGEXP CROPDMG CROPDMGEXP
## 1: TORNADO 0 15 25.0 K 0
## 2: TORNADO 0 0 2.5 K 0
## 3: TORNADO 0 2 25.0 K 0
## 4: TORNADO 0 2 2.5 K 0
## 5: TORNADO 0 2 2.5 K 0
## 6: TORNADO 0 6 2.5 K 0
# Observe each column of required_storms
required_storms$EVTYPE[1:20]
## [1] TORNADO TORNADO TORNADO TORNADO TORNADO TORNADO TORNADO TORNADO
## [9] TORNADO TORNADO TORNADO TORNADO TORNADO TORNADO TORNADO TORNADO
## [17] TORNADO TORNADO TORNADO TORNADO
## 985 Levels: HIGH SURF ADVISORY COASTAL FLOOD ... WND
required_storms$FATALITIES[1:20]
## [1] 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 4 0 0 0 0
required_storms$INJURIES[1:20]
## [1] 15 0 2 2 2 6 1 0 14 0 3 3 26 12 6 50 2 0 0 0
required_storms$PROPDMG[1:20]
## [1] 25.0 2.5 25.0 2.5 2.5 2.5 2.5 2.5 25.0 25.0 2.5
## [12] 2.5 250.0 0.0 25.0 25.0 25.0 25.0 25.0 25.0
required_storms$PROPDMGEXP[1:20]
## [1] K K K K K K K K K K M M K K K K K K K K
## Levels: - ? + 0 1 2 3 4 5 6 7 8 B h H K m M
required_storms$CROPDMG[1:20]
## [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
required_storms$CROPDMGEXP[1:20]
## [1]
## Levels: ? 0 2 B k K m M
Subsetting the required data revealed that the elements of PROPDMGEXP and CROPDMGEXP have mixed cases. Change all elements to upper case.
required_storms$PROPDMGEXP <- toupper(required_storms$PROPDMGEXP)
required_storms$CROPDMGEXP <- toupper(required_storms$CROPDMGEXP)
# Use unique() to observe the elements of PROPDMGEXP and CROPDMGEXP again
unique(required_storms$PROPDMGEXP)
## [1] "K" "M" "" "B" "+" "0" "5" "6" "?" "4" "2" "3" "H" "7" "-" "1" "8"
unique(required_storms$CROPDMGEXP)
## [1] "" "M" "K" "B" "?" "0" "2"
Assign numeric values to the elements of PROPDMGEXP and CROPDMGEXP to be able to quantify economic loss.
# Assign the elements of PROPDMGEXP to quantifiable numeric values
PROPDMGEXP_value <- c("\"\"" = 10^0,
"_" = 10^0,
"+" = 10^0,
"0" = 10^0,
"1" = 10^1,
"2" = 10^2,
"3" = 10^3,
"4" = 10^4,
"5" = 10^5,
"6" = 10^6,
"7" = 10^7,
"8" = 10^8,
"9" = 10^9,
"H" = 10^2,
"K" = 10^3,
"M" = 10^6,
"B" = 10^9)
# Set PROPDMGEXP to the values of PROPDMGEXP_value
required_storms[, PROPDMGEXP := PROPDMGEXP_value[as.character(required_storms[, PROPDMGEXP])]]
required_storms[is.na(PROPDMGEXP), PROPDMGEXP := 10^0]
# Assign the elements of CROPDMGEXP to quantifiable numeric values
CROPDMGEXP_value <- c("\"\"" = 10^0,
"?" = 10^0,
"0" = 10^0,
"K" = 10^3,
"M" = 10^6,
"B" = 10^9)
# Set CROPDMGEXP to the values of CROPDMGEXP_value
required_storms[, CROPDMGEXP := CROPDMGEXP_value[as.character(required_storms[, CROPDMGEXP])]]
required_storms[is.na(CROPDMGEXP), CROPDMGEXP := 10^0]
# View required_storms again after assigning the elements because columns PROPDMGEXP and CROPDMGEXP have changed.
head(required_storms, 15)
## EVTYPE FATALITIES INJURIES PROPDMG PROPDMGEXP CROPDMG CROPDMGEXP
## 1: TORNADO 0 15 25.0 1e+03 0 1
## 2: TORNADO 0 0 2.5 1e+03 0 1
## 3: TORNADO 0 2 25.0 1e+03 0 1
## 4: TORNADO 0 2 2.5 1e+03 0 1
## 5: TORNADO 0 2 2.5 1e+03 0 1
## 6: TORNADO 0 6 2.5 1e+03 0 1
## 7: TORNADO 0 1 2.5 1e+03 0 1
## 8: TORNADO 0 0 2.5 1e+03 0 1
## 9: TORNADO 1 14 25.0 1e+03 0 1
## 10: TORNADO 0 0 25.0 1e+03 0 1
## 11: TORNADO 0 3 2.5 1e+06 0 1
## 12: TORNADO 0 3 2.5 1e+06 0 1
## 13: TORNADO 1 26 250.0 1e+03 0 1
## 14: TORNADO 0 12 0.0 1e+03 0 1
## 15: TORNADO 0 6 25.0 1e+03 0 1
# Aggregate each column
fatalities <- aggregate(FATALITIES ~ EVTYPE, required_storms, sum, na.rm = TRUE)
head(fatalities, 15)
## EVTYPE FATALITIES
## 1 HIGH SURF ADVISORY 0
## 2 COASTAL FLOOD 0
## 3 FLASH FLOOD 0
## 4 LIGHTNING 0
## 5 TSTM WIND 0
## 6 TSTM WIND (G45) 0
## 7 WATERSPOUT 0
## 8 WIND 0
## 9 ? 0
## 10 ABNORMAL WARMTH 0
## 11 ABNORMALLY DRY 0
## 12 ABNORMALLY WET 0
## 13 ACCUMULATED SNOWFALL 0
## 14 AGRICULTURAL FREEZE 0
## 15 APACHE COUNTY 0
injuries <- aggregate(INJURIES ~ EVTYPE, required_storms, sum, na.rm = TRUE)
head(injuries, 15)
## EVTYPE INJURIES
## 1 HIGH SURF ADVISORY 0
## 2 COASTAL FLOOD 0
## 3 FLASH FLOOD 0
## 4 LIGHTNING 0
## 5 TSTM WIND 0
## 6 TSTM WIND (G45) 0
## 7 WATERSPOUT 0
## 8 WIND 0
## 9 ? 0
## 10 ABNORMAL WARMTH 0
## 11 ABNORMALLY DRY 0
## 12 ABNORMALLY WET 0
## 13 ACCUMULATED SNOWFALL 0
## 14 AGRICULTURAL FREEZE 0
## 15 APACHE COUNTY 0
property_damage <- aggregate(PROPDMGEXP ~ EVTYPE, required_storms, sum, na.rm = TRUE)
head(property_damage, 15)
## EVTYPE PROPDMGEXP
## 1 HIGH SURF ADVISORY 1000
## 2 COASTAL FLOOD 1
## 3 FLASH FLOOD 1000
## 4 LIGHTNING 1
## 5 TSTM WIND 1001002
## 6 TSTM WIND (G45) 1000
## 7 WATERSPOUT 1
## 8 WIND 1
## 9 ? 1000
## 10 ABNORMAL WARMTH 4
## 11 ABNORMALLY DRY 2
## 12 ABNORMALLY WET 1
## 13 ACCUMULATED SNOWFALL 4
## 14 AGRICULTURAL FREEZE 6
## 15 APACHE COUNTY 1000
crop_damage <- aggregate(CROPDMGEXP ~ EVTYPE, required_storms, sum, na.rm = TRUE)
head(crop_damage, 15)
## EVTYPE CROPDMGEXP
## 1 HIGH SURF ADVISORY 1
## 2 COASTAL FLOOD 1
## 3 FLASH FLOOD 1
## 4 LIGHTNING 1
## 5 TSTM WIND 4
## 6 TSTM WIND (G45) 1
## 7 WATERSPOUT 1
## 8 WIND 1
## 9 ? 1
## 10 ABNORMAL WARMTH 4
## 11 ABNORMALLY DRY 2
## 12 ABNORMALLY WET 1
## 13 ACCUMULATED SNOWFALL 4
## 14 AGRICULTURAL FREEZE 3000003
## 15 APACHE COUNTY 1
# Sort columns
fatalities <- fatalities[order(-fatalities$FATALITIES),][1:20,]
head(fatalities)
## EVTYPE FATALITIES
## 834 TORNADO 5633
## 130 EXCESSIVE HEAT 1903
## 153 FLASH FLOOD 978
## 275 HEAT 937
## 464 LIGHTNING 816
## 856 TSTM WIND 504
injuries <- injuries[order(-injuries$INJURIES),][1:20,]
head(injuries)
## EVTYPE INJURIES
## 834 TORNADO 91346
## 856 TSTM WIND 6957
## 170 FLOOD 6789
## 130 EXCESSIVE HEAT 6525
## 464 LIGHTNING 5230
## 275 HEAT 2100
names(property_damage) <- c("Events", "PDamage")
property_damage <- property_damage[order(-property_damage$PDamage),][1:20,]
head(property_damage)
## Events PDamage
## 411 HURRICANE/TYPHOON 12046012018
## 834 TORNADO 7533657865
## 170 FLOOD 6541870932
## 402 HURRICANE 3077046048
## 153 FLASH FLOOD 2553660331
## 244 HAIL 2069095207
names(crop_damage) <- c("Events", "CDamage")
crop_damage <- crop_damage[order(-crop_damage$CDamage),][1:20,]
head(crop_damage)
## Events CDamage
## 95 DROUGHT 4143373969
## 411 HURRICANE/TYPHOON 1021011055
## 192 FREEZE 1012002059
## 590 RIVER FLOOD 1005014153
## 427 ICE STORM 1004957045
## 275 HEAT 1003627136
par(mfrow = c(1,2), mar = c(10,3,3,1))
barplot(fatalities$FATALITIES, names.arg = fatalities$EVTYPE, las = 2, col = "pink", ylab = "fatalities", main = "Top 20 fatalities" )
barplot(injuries$INJURIES, names.arg = injuries$EVTYPE, las = 2, col = "light blue", ylab = "injuries", main = "Top 20 injuries")
barplot(property_damage$PDamage, names.arg = property_damage$Events, las = 2, col = "purple", ylab = "fatalities", main = "Top 20 Property damage" )