=============================================
Step 1: Load the dataset from a previous analysis using the NOAA data [weather events database]. For details of how the dataset was created click here.
strm2b <- read.csv("~/storm_refined.csv")
Step 2: Load libraries that will be needed for this assignment.
## load libraries
library(dplyr)
library(leaflet)
Step 3: Prep dataset by selecting weather events in Texas that caused some level of health (fatality/injury) or economic damage (crop/property damage).
## limit NOAA storm dataset (from Reproducible Research) to 1994 and later, eliminate empty lat/long, and add decimal to lat/long
storm <- strm2b %>%
filter(byear >= 1994 & LATITUDE != 0) %>%
mutate(lat = paste(substr(LATITUDE, 1, 2), ".", substr(LATITUDE, 3, length(LATITUDE)), sep = ""),
lng = paste(substr(LONGITUDE, 1, 2), ".", substr(LONGITUDE, 3, length(LONGITUDE)), sep = ""),
color = ifelse(evtCat == "wind_land", "orange",
ifelse(evtCat == "wind_water", "green",
ifelse(evtCat == "water", "blue",
ifelse(evtCat == "heat", "maroon",
ifelse(evtCat == "cold", "pink", "black")))))) %>%
mutate(lat = as.numeric(lat), lng = as.numeric(lng), long = -lng) %>%
select(byear, EVTYPE, evtCat, FATALITIES, INJURIES, STATE, cropDmg, propDmg, lat, long, color)
## limit dataset to Texas events with valid longitude
storm_tx <- storm %>%
filter(STATE == "TX" & long < -50.00)
## limit Texas data to those with health or economic damage
storm_dmg_tx <- storm_tx %>%
filter(FATALITIES > 0 | INJURIES > 0 | cropDmg > 0 | propDmg > 0)
Step 4: Create map of Texas weather events and center around San Antonio.
library(leaflet)
strm_txmap <- storm_dmg_tx %>%
leaflet() %>%
addTiles() %>%
setView(-98.4936, 29.4241, zoom = 10) %>%
addCircleMarkers(lat = storm_dmg_tx$lat,
lng = storm_dmg_tx$long,
popup = paste("<b>Year:</b>", storm_dmg_tx$byear, "<br>",
"<b>Lat / Long:</b>", storm_dmg_tx$lat, storm_dmg_tx$long, "<br>",
"<b>Weather Event Type:</b>", storm_dmg_tx$EVTYPE, "<br>",
"<b>Weather Category:</b>", storm_dmg_tx$evtCat, "<br>",
"<b>Fatalities:</b>", storm_dmg_tx$FATALITIES, "<br>",
"<b>Injuries:</b>", storm_dmg_tx$INJURIES, "<br>",
"<b>Crop Damage (Thousands):</b>", storm_dmg_tx$cropDmg, "<br>",
"<b>Property Damgage (Thousands)</b>:", storm_dmg_tx$propDmg, "<br>"),
color = storm_dmg_tx$color,
fillColor = storm_dmg_tx$color) %>%
addLegend(position = "topleft",
title = "Weather Events Legend",
labels = c("wind_land", "wind_water", "water", "heat", "cold", "other"),
colors = c("orange", "green", "blue", "maroon", "pink", "black"))
strm_txmap