This analysis was carried out using a dataset from NOAA. The time period, years between 1996-2011, was selected due to the availability of the whole official meteorological events resported since 1996 until 2011, thus I decided to discard the reports before 1996. For both question, it was needed to correct the typo of different kinds of events reported and to link them to the list of 48 official NOAA’s events. Regarding the first question,I selected “fatalities” and “injuries” variables because of their relationship with “harmfull efects in human health” .In the other hand, for the second question, regarding “economic impacts” I selected two variables “Crops” and “Properties”. As you might see in the report both question are presented in a graphical form using different pannels for each of the variables.

Data Processing

Libraries are added for future computations

library(dplyr)
library(stringdist)
library(ggplot2)
library(RColorBrewer)
library(gridExtra)

Extraction and storage of data from NOAA’s file:

mainDF<-read.csv(file="C:/Users/pdrs8/Desktop/Coursera/Reproducible Research/Course Project 2/repdata_data_StormData.csv.bz2")

Data processing for the first question (harmfull effects in human health)

Dates are filtered by the mentioned time period, and some typo mistakes are corrected and organized in a uniform manner. The main dataframe was reduced by keeping the variables needed to answer the first question.

humanhealthDF<- mainDF %>% select(BGN_DATE,EVTYPE,FATALITIES,INJURIES) 

humanhealthDF$BGN_DATE<-gsub("0:00:00","",humanhealthDF$BGN_DATE)

humanhealthDF$BGN_DATE<-as.Date(strptime(humanhealthDF$BGN_DATE,"%m/%d/%Y"))

colnames(humanhealthDF)<-c("Date","Event","Fatalities","Injuries")


humanhealthDF <-humanhealthDF %>% 
        arrange(Date) %>% 
        filter(Date>="1996-01-01",Date<="2011-11-30")

humanhealthDF$Event<-toupper(humanhealthDF$Event)

The last dataframe was splitted into two, the firs associated to the “Fatalities” variable and the second for the “Injuries” variable. In order to optimize the future computations, fatalities and injuries with values equal to zero were eliminated.

fatalities<-humanhealthDF %>%
        select(-Injuries) %>% 
        filter(Fatalities!=0)



injuries<-humanhealthDF %>%
        select(-Fatalities) %>% 
        filter(Injuries!=0)

A “csv” file cotaining the 48 official metereological events listed from NOAA was uploaded :

dir1<-"C:/Users/pdrs8/Desktop/Coursera/Reproducible Research/Course Project 2/Events Names.csv"
events<-read.csv(file=dir1, header = TRUE, sep=",")

Fatalities dataset processing

Matching the list of events of fatalities dataset with the official events:

x<-fatalities$Event
y<-events$EVENT

Manually correcting typos mistakes and matching

x<-gsub("TSTM","THUNDERSTORM",x)
x<-gsub("URBAN/SML STREAM FLD","FLOOD",x)
x<-gsub("EXTREME COLD","EXTREME COLD/WIND CHILL",x)
x<-gsub("COLD TEMPERATURE","COLD/WIND CHILL",x)
x<-gsub("EXTREME COLD/WIND CHILL/WIND CHILL","EXTREME COLD/WIND CHILL",x)
x<-gsub("EXTENDED COLD","WINTER WEATHER",x)
x<-gsub("MUDSLIDES","DEBRIS FLOW",x)
x<-gsub("^COLD$","COLD/WIND CHILL",x)
x<-gsub("^DRY MICROBURST$","DUST DEVIL",x)
x<-gsub("^HURRICANE$","HURRICANE (TYPHOON)",x)
x<-gsub("^WINDS$","HIGH WIND",x)
x<-gsub("^COASTAL STORM$","HEAVY RAIN",x)
x<-gsub("^HEAVY SURF$","HIGH SURF",x)
x<-gsub("^FOG$","DENSE FOG",x)
x<-gsub("^MIXED PRECIP$","SLEET",x)
x<-gsub("^HYPOTHERMIA/EXPOSURE$","EXTREME COLD/WIND CHILL",x)
x<-gsub("^WIND$","HIGH WIND",x)
x<-gsub("MUDSLIDE","DEBRIS FLOW",x)
x<-gsub("LANDSLIDES","DEBRIS FLOW",x)
x<-gsub("^BLACK ICE$","SLEET",x)
x<-gsub("^HEAVY SURF AND WIND$","HIGH SURF",x)
x<-gsub("^SNOW SQUALLS$","HEAVY SNOW",x)
x<-gsub("^COASTALSTORM$","HEAVY RAIN",x)
x<-gsub("^SNOW AND ICE$","SLEET",x)
x<-gsub("^FROST$","FREEZING FOG",x)
x<-gsub("^ICY ROADS$","SLEET",x)
x<-gsub("^SNOW$","HEAVY SNOW",x)
x<-gsub("^GLAZE$","SLEET",x)
x<-gsub("^SNOW SQUALL$","HEAVY SNOW",x)
x<-gsub("^RIVER FLOOD","LAKESHOREFLOOD",x)
x<-gsub("^RIVER FLOODING","LAKESHOREFLOOD",x)
x<-gsub("^HYPERTHERMIA/EXPOSURE$","EXTREME COLD/WIND CHILL",x)
x<-gsub("^WINTRY MIX$","SLEET",x)
x<-gsub("^RECORD HEAT$","EXCESSIVE HEAT",x)
x<-gsub("^HEAVY SEAS$","HIGH SURF",x)
x<-gsub("^LIGHT SNOW$","COLD/WIND CHILL",x)
x<-gsub("^HIGH WATER$","FLOOD",x)
x<-gsub("^ROUGH SEAS$","STORM SURGE/TIDE",x)
x<-gsub("^FALLING SNOW/ICE$","ICE STORM",x)
x<-gsub("^ICE ON ROAD$","SLEET",x)
x<-gsub("^DROWNING$","FLOOD",x)
x<-gsub("^HEAVY SURF/HIGH SURF$","HIGH SURF",x)
x<-gsub("^LANDSLIDE$","DEBRIS FLOW",x)

Automatic matching between event lists, for this purpose “amatch” function was employed . The total fatalities during this period was obtainded using “aggregate” function and then the results were reduced by using the last quartile thus showing the events with greatest amount of fatalities:

xDF<-data.frame("Events"=x,"Official Event Equivalence"=y[amatch(x,y, maxDist = 8)])

fatalities$Event<-xDF$Official.Event.Equivalence

totalfatalities<-aggregate(fatalities$Fatalities,by=list(fatalities$Event),sum)
colnames(totalfatalities)<-c("Event","Fatalities")

topfatalities<-totalfatalities[ totalfatalities$Fatalities> quantile(totalfatalities$Fatalities , 0.75 ) , ]

topfatalities <- transform(topfatalities, Event= as.factor(Event))
topfatalities <-transform(topfatalities,Event=reorder(Event,-Fatalities))

Injuries dataset processing

Matching the list of events of injuries dataset with the official events:

x1<-injuries$Event
y1<-events$EVENT

Manually correcting typos mistakes and matching

x1<-gsub("TSTM","THUNDERSTORM",x1)
x1<-gsub("URBAN/SML STREAM FLD","FLOOD",x1)
x1<-gsub("EXTREME COLD","EXTREME COLD/WIND CHILL",x1)
x1<-gsub("COLD TEMPERATURE","COLD/WIND CHILL",x1)
x1<-gsub("EXTREME COLD/WIND CHILL/WIND CHILL","EXTREME COLD/WIND CHILL",x1)
x1<-gsub("EXTENDED COLD","WINTER WEATHER",x1)
x1<-gsub("MUDSLIDES","DEBRIS FLOW",x1)
x1<-gsub("^COLD$","COLD/WIND CHILL",x1)
x1<-gsub("^DRY MICROBURST$","DUST DEVIL",x1)
x1<-gsub("^HURRICANE$","HURRICANE (TYPHOON)",x1)
x1<-gsub("^WINDS$","HIGH WIND",x1)
x1<-gsub("^COASTAL STORM$","HEAVY RAIN",x1)
x1<-gsub("^HEAVY SURF$","HIGH SURF",x1)
x1<-gsub("^FOG$","DENSE FOG",x1)
x1<-gsub("^MIXED PRECIP$","SLEET",x1)
x1<-gsub("^HYPOTHERMIA/EXPOSURE$","EXTREME COLD/WIND CHILL",x1)
x1<-gsub("^WIND$","HIGH WIND",x1)
x1<-gsub("MUDSLIDE","DEBRIS FLOW",x1)
x1<-gsub("LANDSLIDES","DEBRIS FLOW",x1)
x1<-gsub("^BLACK ICE$","SLEET",x1)
x1<-gsub("^HEAVY SURF AND WIND$","HIGH SURF",x1)
x1<-gsub("^SNOW SQUALLS$","HEAVY SNOW",x1)
x1<-gsub("^COASTALSTORM$","HEAVY RAIN",x1)
x1<-gsub("^SNOW AND ICE$","SLEET",x1)
x1<-gsub("^FROST$","FREEZING FOG",x1)
x1<-gsub("^ICY ROADS$","SLEET",x1)
x1<-gsub("^SNOW$","HEAVY SNOW",x1)
x1<-gsub("^GLAZE$","SLEET",x1)
x1<-gsub("^SNOW SQUALL$","HEAVY SNOW",x1)
x1<-gsub("^RIVER FLOOD","LAKESHOREFLOOD",x1)
x1<-gsub("^RIVER FLOODING","LAKESHOREFLOOD",x1)
x1<-gsub("^HYPERTHERMIA/EXPOSURE$","EXTREME COLD/WIND CHILL",x1)
x1<-gsub("^WINTRY MIX$","SLEET",x1)
x1<-gsub("^RECORD HEAT$","EXCESSIVE HEAT",x1)
x1<-gsub("^HEAVY SEAS$","HIGH SURF",x1)
x1<-gsub("^LIGHT SNOW$","COLD/WIND CHILL",x1)
x1<-gsub("^HIGH WATER$","FLOOD",x1)
x1<-gsub("^ROUGH SEAS$","STORM SURGE/TIDE",x1)
x1<-gsub("^FALLING SNOW/ICE$","ICE STORM",x1)
x1<-gsub("^ICE ON ROAD$","SLEET",x1)
x1<-gsub("^DROWNING$","FLOOD",x1)
x1<-gsub("^HEAVY SURF/HIGH SURF$","HIGH SURF",x1)
x1<-gsub("^LANDSLIDE$","DEBRIS FLOW",x1)
x1<-gsub("^HEAVY SURF/HIGH SURF$","HIGH SURF",x1)
x1<-gsub("^TORRENTIAL RAINFALL$","HEAVY RAIN",x1)
x1<-gsub("^HEAT WAVE$","EXCESSIVE HEAT",x1)
x1<-gsub("^HURRICANE EDOUARD$","HURRICANE (TYPHOON)",x1)
x1<-gsub("^TYPHOON$","HURRICANE (TYPHOON)",x1)
x1<-gsub("^COASTAL FLOODING/EROSION$","FLOOD",x1)
x1<-gsub("^EXCESSIVE SNOW$","HEAVY SNOW",x1)
x1<-gsub("^ICE ROADS$","SLEET",x1)
x1<-gsub("^UNSEASONABLY WARM$","HEAT",x1)
x1<-gsub("^NON-SEVERE WIND DAMAGE$","HIGH WIND",x1)
x1<-gsub("^WARM WEATHER$","HEAT",x1)
x1<-gsub("^ROGUE WAVE$","HIGH SURF",x1)

Automatic matching between event lists, for this purpose “amatch” function was employed . The total injuries during this period was obtainded using “aggregate” function and then the results were reduced by using the last quartile thus showing the events with greatest amount of injuries:

x1DF<-data.frame("Events"=x1,"Official Event Equivalence"=y1[amatch(x1,y1, maxDist = 8)])

injuries$Event<-x1DF$Official.Event.Equivalence

totalinjuries<-aggregate(injuries$Injuries,by=list(injuries$Event),sum)

colnames(totalinjuries)<-c("Event","Injuries")

topinjuries<-totalinjuries[ totalinjuries$Injuries> quantile(totalinjuries$Injuries , 0.75 ) , ]

topinjuries <- transform(topinjuries, Event= as.factor(Event))
topinjuries<-transform(topinjuries,Event=reorder(Event,-Injuries))

Data processing for the second question (harmfull effects in human health)

Dates are filtered by the mentioned time period, and some typo mistakes are corrected and organized in a uniform manner. The main dataframe was reduced by keeping the variables needed to answer the second question.

economyDF<- mainDF %>% select(BGN_DATE,EVTYPE,PROPDMG,PROPDMGEXP,CROPDMG,CROPDMGEXP) 

economyDF$BGN_DATE<-gsub("0:00:00","",economyDF$BGN_DATE)

economyDF$BGN_DATE<-as.Date(strptime(economyDF$BGN_DATE,"%m/%d/%Y"))

colnames(economyDF)<-c("Date","Event","Properties","PropertiesExp","Crops","CropsExp")

economyDF <-economyDF %>% 
        arrange(Date) %>% 
        filter(Date>="1996-01-01",Date<="2011-11-30")

economyDF$Event<-toupper(economyDF$Event)

The last dataframe was splitted into two, the firs associated to the “Crops” variable and the second for the “Properties” variable. In order to optimize the future computations, crops and properties with values equal to zero were eliminated.

properties<-economyDF %>%
        select(-c(Crops,CropsExp)) %>% 
        filter(Properties!=0)



crops<-economyDF %>%
        select(-c(Properties,PropertiesExp)) %>% 
        filter(Crops!=0)

Crops dataset processing

Transforming the values of crop and it’s exponent into a single column:

crops$CropsExp<-gsub("K",1000,crops$CropsExp)
crops$CropsExp<-gsub("M",1000000,crops$CropsExp)
crops$CropsExp<-gsub("B",1000000000,crops$CropsExp)

crops<-transform(crops,CropsExp=as.numeric(crops$CropsExp))

crops<- crops %>% 
        mutate(CropsF=Crops*CropsExp) %>% 
        select(Event,CropsF)

Matching the list of events of crops dataset with the official events:

x2<-crops$Event
y2<-events$EVENT

Manually correcting typos mistakes and matching

x2<-gsub("TSTM","THUNDERSTORM",x2)
x2<-gsub("URBAN/SML STREAM FLD","FLOOD",x2)
x2<-gsub("EXTREME COLD","EXTREME COLD/WIND CHILL",x2)
x2<-gsub("COLD TEMPERATURE","COLD/WIND CHILL",x2)
x2<-gsub("EXTREME COLD/WIND CHILL/WIND CHILL","EXTREME COLD/WIND CHILL",x2)
x2<-gsub("EXTENDED COLD","WINTER WEATHER",x2)
x2<-gsub("MUDSLIDES","DEBRIS FLOW",x2)
x2<-gsub("^COLD$","COLD/WIND CHILL",x2)
x2<-gsub("^DRY MICROBURST$","DUST DEVIL",x2)
x2<-gsub("^HURRICANE$","HURRICANE (TYPHOON)",x2)
x2<-gsub("^WINDS$","HIGH WIND",x2)
x2<-gsub("^COASTAL STORM$","HEAVY RAIN",x2)
x2<-gsub("^HEAVY SURF$","HIGH SURF",x2)
x2<-gsub("^FOG$","DENSE FOG",x2)
x2<-gsub("^MIXED PRECIP$","SLEET",x2)
x2<-gsub("^HYPOTHERMIA/EXPOSURE$","EXTREME COLD/WIND CHILL",x2)
x2<-gsub("^WIND$","HIGH WIND",x2)
x2<-gsub("MUDSLIDE","DEBRIS FLOW",x2)
x2<-gsub("LANDSLIDES","DEBRIS FLOW",x2)
x2<-gsub("^BLACK ICE$","SLEET",x2)
x2<-gsub("^HEAVY SURF AND WIND$","HIGH SURF",x2)
x2<-gsub("^SNOW SQUALLS$","HEAVY SNOW",x2)
x2<-gsub("^COASTALSTORM$","HEAVY RAIN",x2)
x2<-gsub("^SNOW AND ICE$","SLEET",x2)
x2<-gsub("^FROST$","FREEZING FOG",x2)
x2<-gsub("^ICY ROADS$","SLEET",x2)
x2<-gsub("^SNOW$","HEAVY SNOW",x2)
x2<-gsub("^GLAZE$","SLEET",x2)
x2<-gsub("^SNOW SQUALL$","HEAVY SNOW",x2)
x2<-gsub("^RIVER FLOOD","LAKESHOREFLOOD",x2)
x2<-gsub("^RIVER FLOODING","LAKESHOREFLOOD",x2)
x2<-gsub("^HYPERTHERMIA/EXPOSURE$","EXTREME COLD/WIND CHILL",x2)
x2<-gsub("^WINTRY MIX$","SLEET",x2)
x2<-gsub("^RECORD HEAT$","EXCESSIVE HEAT",x2)
x2<-gsub("^HEAVY SEAS$","HIGH SURF",x2)
x2<-gsub("^LIGHT SNOW$","COLD/WIND CHILL",x2)
x2<-gsub("^HIGH WATER$","FLOOD",x2)
x2<-gsub("^ROUGH SEAS$","STORM SURGE/TIDE",x2)
x2<-gsub("^FALLING SNOW/ICE$","ICE STORM",x2)
x2<-gsub("^ICE ON ROAD$","SLEET",x2)
x2<-gsub("^DROWNING$","FLOOD",x2)
x2<-gsub("^HEAVY SURF/HIGH SURF$","HIGH SURF",x2)
x2<-gsub("^LANDSLIDE$","DEBRIS FLOW",x2)
x2<-gsub("^HEAVY SURF/HIGH SURF$","HIGH SURF",x2)
x2<-gsub("^TORRENTIAL RAINFALL$","HEAVY RAIN",x2)
x2<-gsub("^HEAT WAVE$","EXCESSIVE HEAT",x2)
x2<-gsub("^HURRICANE EDOUARD$","HURRICANE (TYPHOON)",x2)
x2<-gsub("^TYPHOON$","HURRICANE (TYPHOON)",x2)
x2<-gsub("^COASTAL FLOODING/EROSION$","FLOOD",x2)
x2<-gsub("^EXCESSIVE SNOW$","HEAVY SNOW",x2)
x2<-gsub("^ICE ROADS$","SLEET",x2)
x2<-gsub("^UNSEASONABLY WARM$","HEAT",x2)
x2<-gsub("^NON-SEVERE WIND DAMAGE$","HIGH WIND",x2)
x2<-gsub("^WARM WEATHER$","HEAT",x2)
x2<-gsub("^ROGUE WAVE$","HIGH SURF",x2)
x2<-gsub("^DAMAGING FREEZE$","FROST/FREEZE",x2)
x2<-gsub("^UNSEASONABLE COLD$","COLD/WIND CHILL",x2)
x2<-gsub("^EARLY FROST$","FROST/FREEZE",x2)
x2<-gsub("^HEAVY RAIN/HIGH SURF$","STORM SURGE/TIDE",x2)
x2<-gsub("^UNSEASONABLY COLD$","COLD/WIND CHILL",x2)
x2<-gsub("^AGRICULTURAL FREEZE$","FROST/FREEZE",x2)
x2<-gsub("^RAIN$","HEAVY RAIN",x2)

Automatic matching between event lists, for this purpose “amatch” function was employed . The total crops during this period was obtainded using “aggregate” function and then the results were reduced by using the last quartile thus showing the events with greatest amount of crops:

x2DF<-data.frame("Events"=x2,"Official Event Equivalence"=y2[amatch(x2,y2, maxDist = 9)])
crops$Event<-x2DF$Official.Event.Equivalence
totalcrops<-aggregate(crops$CropsF,by=list(crops$Event),sum)
colnames(totalcrops)<-c("Event","Crops")

topcrops<-totalcrops[ totalcrops$Crops> quantile(totalcrops$Crops , 0.75 ) , ]

topcrops <- transform(topcrops, Event= as.factor(Event))
topcrops<-transform(topcrops,Event=reorder(Event,-Crops))

Crops dataset processing

Transforming the values of properties and it’s exponent into a single column:

properties$PropertiesExp<-gsub("K",1000,properties$PropertiesExp)
properties$PropertiesExp<-gsub("M",1000000,properties$PropertiesExp)
properties$PropertiesExp<-gsub("B",1000000000,properties$PropertiesExp)


properties<-transform(properties,PropertiesExp=as.numeric(properties$PropertiesExp))

properties<- properties %>% 
        mutate(PropertiesF=Properties*PropertiesExp) %>% 
        select(Event,PropertiesF)

Matching the list of events of properties dataset with the official events:

x3<-properties$Event
y3<-events$EVENT

Manually correcting typos mistakes and matching

x3<-gsub("TSTM","THUNDERSTORM",x3)
x3<-gsub("URBAN/SML STREAM FLD","FLOOD",x3)
x3<-gsub("EXTREME COLD","EXTREME COLD/WIND CHILL",x3)
x3<-gsub("COLD TEMPERATURE","COLD/WIND CHILL",x3)
x3<-gsub("EXTREME COLD/WIND CHILL/WIND CHILL","EXTREME COLD/WIND CHILL",x3)
x3<-gsub("EXTENDED COLD","WINTER WEATHER",x3)
x3<-gsub("MUDSLIDES","DEBRIS FLOW",x3)
x3<-gsub("^COLD$","COLD/WIND CHILL",x3)
x3<-gsub("^DRY MICROBURST$","DUST DEVIL",x3)
x3<-gsub("^HURRICANE$","HURRICANE (TYPHOON)",x3)
x3<-gsub("^WINDS$","HIGH WIND",x3)
x3<-gsub("^COASTAL STORM$","HEAVY RAIN",x3)
x3<-gsub("^HEAVY SURF$","HIGH SURF",x3)
x3<-gsub("^FOG$","DENSE FOG",x3)
x3<-gsub("^MIXED PRECIP$","SLEET",x3)
x3<-gsub("^HYPOTHERMIA/EXPOSURE$","EXTREME COLD/WIND CHILL",x3)
x3<-gsub("^WIND$","HIGH WIND",x3)
x3<-gsub("MUDSLIDE","DEBRIS FLOW",x3)
x3<-gsub("LANDSLIDES","DEBRIS FLOW",x3)
x3<-gsub("^BLACK ICE$","SLEET",x3)
x3<-gsub("^HEAVY SURF AND WIND$","HIGH SURF",x3)
x3<-gsub("^SNOW SQUALLS$","HEAVY SNOW",x3)
x3<-gsub("^COASTALSTORM$","HEAVY RAIN",x3)
x3<-gsub("^SNOW AND ICE$","SLEET",x3)
x3<-gsub("^FROST$","FREEZING FOG",x3)
x3<-gsub("^ICY ROADS$","SLEET",x3)
x3<-gsub("^SNOW$","HEAVY SNOW",x3)
x3<-gsub("^GLAZE$","SLEET",x3)
x3<-gsub("^SNOW SQUALL$","HEAVY SNOW",x3)
x3<-gsub("^RIVER FLOOD","LAKESHOREFLOOD",x3)
x3<-gsub("^RIVER FLOODING","LAKESHOREFLOOD",x3)
x3<-gsub("^HYPERTHERMIA/EXPOSURE$","EXTREME COLD/WIND CHILL",x3)
x3<-gsub("^WINTRY MIX$","SLEET",x3)
x3<-gsub("^RECORD HEAT$","EXCESSIVE HEAT",x3)
x3<-gsub("^HEAVY SEAS$","HIGH SURF",x3)
x3<-gsub("^LIGHT SNOW$","COLD/WIND CHILL",x3)
x3<-gsub("^HIGH WATER$","FLOOD",x3)
x3<-gsub("^ROUGH SEAS$","STORM SURGE/TIDE",x3)
x3<-gsub("^FALLING SNOW/ICE$","ICE STORM",x3)
x3<-gsub("^ICE ON ROAD$","SLEET",x3)
x3<-gsub("^DROWNING$","FLOOD",x3)
x3<-gsub("^HEAVY SURF/HIGH SURF$","HIGH SURF",x3)
x3<-gsub("^LANDSLIDE$","DEBRIS FLOW",x3)
x3<-gsub("^HEAVY SURF/HIGH SURF$","HIGH SURF",x3)
x3<-gsub("^TORRENTIAL RAINFALL$","HEAVY RAIN",x3)
x3<-gsub("^HEAT WAVE$","EXCESSIVE HEAT",x3)
x3<-gsub("^HURRICANE EDOUARD$","HURRICANE (TYPHOON)",x3)
x3<-gsub("^TYPHOON$","HURRICANE (TYPHOON)",x3)
x3<-gsub("^COASTAL FLOODING/EROSION$","FLOOD",x3)
x3<-gsub("^EXCESSIVE SNOW$","HEAVY SNOW",x3)
x3<-gsub("^ICE ROADS$","SLEET",x3)
x3<-gsub("^UNSEASONABLY WARM$","HEAT",x3)
x3<-gsub("^NON-SEVERE WIND DAMAGE$","HIGH WIND",x3)
x3<-gsub("^WARM WEATHER$","HEAT",x3)
x3<-gsub("^ROGUE WAVE$","HIGH SURF",x3)
x3<-gsub("^DAMAGING FREEZE$","FROST/FREEZE",x3)
x3<-gsub("^UNSEASONABLE COLD$","COLD/WIND CHILL",x3)
x3<-gsub("^EARLY FROST$","FROST/FREEZE",x3)
x3<-gsub("^HEAVY RAIN/HIGH SURF$","STORM SURGE/TIDE",x3)
x3<-gsub("^UNSEASONABLY COLD$","COLD/WIND CHILL",x3)
x3<-gsub("^AGRICULTURAL FREEZE$","FROST/FREEZE",x3)
x3<-gsub("^RAIN$","HEAVY RAIN",x3)
x3<-gsub("^MICROBURST$","DUST DEVIL",x3)
x3<-gsub("^LANDSLUMP$","DEBRIS FLOW",x3)
x3<-gsub("^DOWNBURST$","DUST DEVIL",x3)
x3<-gsub("^GUSTY WIND/HVY RAIN$","HEAVY RAIN",x3)
x3<-gsub("^ICE JAM FLOOD","FLOOD",x3)
x3<-gsub("^BEACH EROSION$","DEBRIS FLOW",x3)
x3<-gsub("^WIND DAMAGE$","HIGH WIND",x3)
x3<-gsub("^LIGHT SNOWFALL$","WINTER WEATHER",x3)
x3<-gsub("^MIXED PRECIPITATION$","SLEET",x3)
x3<-gsub("^MUD SLIDE$","DEBRIS FLOW",x3)
x3<-gsub("^DAM BREAK$","DEBRIS FLOW",x3)
x3<-gsub("^THUNDERSTORM WIND AND LIGHTNING$","THUNDERSTORM WIND",x3)
x3<-gsub("^WET MICROBURST$","DUST DEVIL",x3)
x3<-gsub("^COASTAL  FLOODING/EROSION$","FLOOD",x3)
x3<-gsub("^ROCK SLIDE$","DEBRIS FLOW",x3)
x3<-gsub("^FREEZE$","FROST/FREEZE",x3)
x3<-gsub("^GUSTY WIND/HAIL$","SLEET",x3)
x3<-gsub("^WIND AND WAVE$","STORM SURGE/TIDE",x3)
x3<-gsub("^LANDSPOUT$","TORNADO",x3)
x3<-gsub("^LIGHT FREEZING RAIN$","WINTER WEATHER",x3)
x3<-gsub("^BLOWING DUST$","DUST STORM",x3)
x3<-gsub("^NON-THUNDERSTORM WIND$","HIGH WIND",x3)
x3<-gsub("HIGH SURF ADVISORY$","HIGH SURF",x3)

Automatic matching between event lists, for this purpose “amatch” function was employed . The total properties during this period was obtainded using “aggregate” function and then the results were reduced by using the last quartile thus showing the events with greatest amount of properties:

x3DF<-data.frame("Events"=x3,"Official Event Equivalence"=y3[amatch(x3,y3, maxDist = 9)])

properties$Event<-x3DF$Official.Event.Equivalence

totalproperties<-aggregate(properties$PropertiesF,by=list(properties$Event),sum)

colnames(totalproperties)<-c("Event","Properties")

topproperties<-totalproperties[totalproperties$Properties> quantile(totalproperties$Properties , 0.75 ) , ]

topproperties<-transform(topproperties, Event= as.factor(Event))

topproperties<-transform(topproperties,Event=reorder(Event,-Properties))

Results

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

Plot total fatalities vs event type:

myColors <- brewer.pal(6, "Set1")
g1<-ggplot(topfatalities,aes(x=Event,y=Fatalities,fill=Event))+
        geom_bar(stat="identity")+scale_colour_manual(name = "spray", values=myColors)+theme_bw()+
        theme(axis.text.x=element_blank(),plot.title = element_text(size=15),legend.text = element_text(size = 10),legend.title = element_blank())+
        ggtitle("Total fatalities due to meteorogical events between 1996-2011")+
        xlab("Event type")+ylab("Number of fatalities")

Plot total injuries vs event type:

g2<-ggplot(topinjuries,aes(x=Event,y=Injuries,fill=Event))+
                geom_bar(stat="identity")+scale_colour_manual(name = "spray", values=myColors)+theme_bw()+
        theme(axis.text.x=element_blank(),plot.title = element_text(size=15),legend.text = element_text(size = 10),legend.title = element_blank())+
        ggtitle("Total injuries due to meteorogical events between 1996-2011")+
        xlab("Event type")+ylab("Number of injuries")

Ploting both graphs in different pannels in the same window:

grid.arrange(g1,g2,ncol=1,nrow=2)

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

Plot total crops vs event type:

g3<-ggplot(topcrops,aes(x=Event,y=Crops,fill=Event))+
        geom_bar(stat="identity")+scale_colour_manual(name = "spray", values=myColors)+theme_bw()+
        theme(axis.text.x=element_blank(),plot.title = element_text(size=15),legend.text = element_text(size = 10),legend.title = element_blank())+
        ggtitle("Total economic impact in crops due to meteorogical events between 1996-2011")+
        xlab("Event type")+ylab("USD Lost")

Plot total properties vs event type:

g4<-ggplot(topproperties,aes(x=Event,y=Properties,fill=Event))+
        geom_bar(stat="identity")+scale_colour_manual(name = "spray", values=myColors)+theme_bw()+
        theme(axis.text.x=element_blank(),plot.title = element_text(size=15),legend.text = element_text(size = 10),legend.title = element_blank())+
        ggtitle("Total economic impact in properties due to meteorogical events between 1996-2011")+
        xlab("Event type")+ylab("USD Lost")

Ploting both graphs in different pannels in the same window:

grid.arrange(g3,g4,ncol=1,nrow=2)