## New names:
## Rows: 665414 Columns: 22
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," chr
## (4): Address, State, County, City dbl (17): ...1, O3 Mean, O3 1st Max Value, O3
## 1st Max Hour, O3 AQI, CO Mean... date (1): Date
## ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
## Specify the column types or set `show_col_types = FALSE` to quiet this message.
## • `` -> `...1`
## Rows: 8627181 Columns: 14
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (8): EventId, Type, Severity, TimeZone, AirportCode, City, County, State
## dbl (4): Precipitation(in), LocationLat, LocationLng, ZipCode
## dttm (2): StartTime(UTC), EndTime(UTC)
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#should clean data remove NA's etc
#making a plot for amount of severe weather events by state using weather dataset
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
library(lubridate)
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
## EventId Type Severity
## Length:8627181 Length:8627181 Length:8627181
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
##
##
##
##
## StartTime(UTC) EndTime(UTC)
## Min. :2016-01-01 05:00:00.00 Min. :2016-01-01 05:15:00.00
## 1st Qu.:2017-10-07 22:15:00.00 1st Qu.:2017-10-07 23:13:00.00
## Median :2019-05-19 05:35:00.00 Median :2019-05-19 06:53:00.00
## Mean :2019-06-17 01:49:22.55 Mean :2019-06-17 03:13:21.03
## 3rd Qu.:2021-02-15 21:14:00.00 3rd Qu.:2021-02-15 22:51:00.00
## Max. :2022-12-31 23:55:00.00 Max. :2023-01-01 00:00:00.00
##
## Precipitation(in) TimeZone AirportCode LocationLat
## Min. : 0.0000 Length:8627181 Length:8627181 Min. :24.56
## 1st Qu.: 0.0000 Class :character Class :character 1st Qu.:34.60
## Median : 0.0000 Mode :character Mode :character Median :39.35
## Mean : 0.0929 Mean :38.79
## 3rd Qu.: 0.0500 3rd Qu.:43.06
## Max. :1104.1300 Max. :48.94
##
## LocationLng City County State
## Min. :-124.56 Length:8627181 Length:8627181 Length:8627181
## 1st Qu.: -97.82 Class :character Class :character Class :character
## Median : -89.77 Mode :character Mode :character Mode :character
## Mean : -91.91
## 3rd Qu.: -81.95
## Max. : -67.79
##
## ZipCode
## Min. : 1022
## 1st Qu.:31216
## Median :53913
## Mean :52412
## 3rd Qu.:73503
## Max. :99362
## NA's :69199
#converts character class state and county to factor - should do this with year to and look at over the years
weather_data$State <- as.factor(weather_data$State)
weather_data$County <- as.factor(weather_data$County)
#creates a new column with the year of the event's start
weather_data <- weather_data %>% mutate(year = year(`StartTime(UTC)`))
#creates a dataset of the mean precipitation for each state
state_precip_mean <- weather_data %>% group_by(State) %>% summarise(precip_mean = mean(`Precipitation(in)`))
#creates a gg bar plot based on the average amount of precipitation for each state
#would be really cool if could make a map of the us and the state colors the average amount of precipitation
ggplot(state_precip_mean, aes(x = State, y = precip_mean)) + geom_col()
#add new coulmn for how long weather event lasted
weather_data <- weather_data %>% mutate(event_duration = (`EndTime(UTC)`- `StartTime(UTC)`))
#new dataset for event type, severity and duration
weather_events <- weather_data %>% dplyr::select(State, Type, Severity, event_duration, year)
#new dataset just including events in Ohio, relevant for the bar plots becuase the events of each state vary alot, this could be due to size of state(becuase texas covers more land than delaware they eill obviously have more events), i just chose Ohio to get a closer look at the distrabution of events and severity
ohio_events <- weather_data %>% filter(State == "OH")
#ggplot bar plot of the distrabution of types of events for each state
ggplot(weather_events, aes(x = State)) +
geom_bar(width = .5, aes(fill = Type)) +
labs(title = "breakdown of type of events for each state",
subtitle = "bar chart",
caption = "source: weather_data") +
theme(axis.text.x = element_text(angle = 90, vjust = 0.6))
#ggplot bar plot of the distrabution of severity of events for each state
ggplot(weather_events, aes(x = State)) +
geom_bar(width = .5, aes(fill = Severity)) +
labs(title = "breakdown of severity of events for each state",
subtitle = "bar chart",
caption = "source: weather_data") +
theme(axis.text.x = element_text(angle = 90, vjust = 0.6))
#ggplot bar plot of the distrabution of severity of events for each county in Ohio
#did this becuase the amount of events per state varied a lot so this was a way to narrow down the data to better see the distrabution of severity
ggplot(ohio_events, aes(x = County)) +
geom_bar(width = .5, aes(fill = Severity)) +
labs(title = "breakdown of severity of events for each county in Ohio",
subtitle = "bar chart",
caption = "source: weather_data") +
theme(axis.text.x = element_text(angle = 90, vjust = 0.6))
#have to look at dataset and figure out why these plots have so many severity options, try to lower it to light, moderate, heavy, severe.
#dot plot similar to the one in the DataViz-ggplot2.Rmd in the code chunk at line 434 with the diamond dataset
#first convert duration to a numeric
weather_events <- weather_events %>% mutate(event_duration_numeric = as.numeric(event_duration))
#on this plot the x axis is the severity and the y axis is the duration of the event
ggplot(weather_events %>% filter(Type %in% c("Rain","Snow")), aes(x = Severity, y = event_duration_numeric)) + geom_point()
# ylab("event duration")
#+ xlab("severity")
#should fix the y axis measuring- not have in scientific notation
library(streamgraph)
summary(weather_events)
## State Type Severity event_duration
## TX : 583234 Length:8627181 Length:8627181 Length:8627181
## MN : 452099 Class :character Class :character Class :difftime
## MI : 418795 Mode :character Mode :character Mode :numeric
## FL : 373421
## NC : 364605
## CA : 351660
## (Other):6083367
## year event_duration_numeric
## Min. :2016 Min. : 0
## 1st Qu.:2017 1st Qu.: 1200
## Median :2019 Median : 2400
## Mean :2019 Mean : 5038
## 3rd Qu.:2021 3rd Qu.: 4560
## Max. :2022 Max. :97951920
##
#this should make an interactive graph like the one in the DataViz-ggplot2.Rmd file in the code chunk at line 700 that used baby name data
#this plot should show year along x axis and each state will have a horizontal line that will be proportional to the amount of events they had by year
weather_events %>%
filter(grepl("^La", State)) %>%
group_by(year, State) %>%
tally %>%
streamgraph("State", "n", "year")
## Warning in widget_html(name, package, id = x$id, style = css(width =
## validateCssUnit(sizeInfo$width), : streamgraph_html returned an object of class
## `list` instead of a `shiny.tag`.
## Warning: `bindFillRole()` only works on htmltools::tag() objects (e.g., div(),
## p(), etc.), not objects of type 'list'.
#this code ran successfully but the graph never showed up on my computer it just showed a blank gray square where the graph would be