--- title: "Airline Reliability Dashboard: New York Flights 2013" output: flexdashboard::flex_dashboard: orientation: columns --- ```{r setup, include=FALSE} library(flexdashboard) library(ggplot2) library(dplyr) library(plotly) library(nycflights13) library(forcats) library(tidyr) flights_new <- flights flights_new$dep_del_status <- ifelse(flights_new$dep_delay>=15, 1, 0) flights_new$arr_del_status <- ifelse(flights_new$arr_delay>=15, 1, 0) ``` Column {data-width=650} ----------------------------------------------------------------------- ### Proportion of Flights Delayed (Departure and Arrival) by Carrier ```{r} flights_delay <- flights_new %>% group_by(carrier) %>% summarise(dep_del = sum(dep_del_status,na.rm = TRUE), arr_del = sum(arr_del_status,na.rm = TRUE), n = n(), prop_dep_del = round(dep_del/n,2), prop_arr_del = round(arr_del/n,2) ) flights_delay$carrier <- fct_reorder(flights_delay$carrier, flights_delay$prop_dep_del) flights_delay_long <- flights_delay %>% gather(key = "Delay", value = "prop", 5:6) flights_delay_long$Delay <- factor(flights_delay_long$Delay, levels = c("prop_dep_del","prop_arr_del"), labels = c("Departure","Arrival"), order = TRUE) p1 <- ggplot(flights_delay_long, aes(x = carrier, y = prop)) + geom_bar(stat = "identity", fill = "steelblue") + facet_grid(.~Delay) + labs(x = "Carrier Code", y = "Proportion on time (+/- 15 mins of schedule)") + theme_grey() ggplotly(p1) ``` Column {data-width=350} ----------------------------------------------------------------------- ### Proportion of Flights Delayed (Departure) by Carrier by Month ```{r} flights_delay_month <- flights_new %>% group_by(carrier,month) %>% summarise(dep_del = sum(dep_del_status,na.rm = TRUE), arr_del = sum(arr_del_status,na.rm = TRUE), n = n(), prop_dep_del = round(dep_del/n,2), prop_arr_del = round(arr_del/n,2) ) flights_delay_month$carrier <- fct_reorder(flights_delay_month$carrier, flights_delay_month$prop_dep_del) p2 <- ggplot(flights_delay_month, aes(x = carrier, y = as.factor(month))) + geom_tile(aes(fill = prop_dep_del)) + scale_fill_gradient(name = "Proportion", low = "white",high = "steelblue") + labs(x = "Carrier", y = "Month") ggplotly(p2) ``` ### Proportion of Flights Delayed (Arrival) by Carrier by Month ```{r} flights_delay_month <- flights_new %>% group_by(carrier,month) %>% summarise(dep_del = sum(dep_del_status,na.rm = TRUE), arr_del = sum(arr_del_status,na.rm = TRUE), n = n(), prop_dep_del = round(dep_del/n,2), prop_arr_del = round(arr_del/n,2) ) flights_delay_month$carrier <- fct_reorder(flights_delay_month$carrier, flights_delay_month$prop_dep_del) p3 <- ggplot(flights_delay_month, aes(x = carrier, y = as.factor(month))) + geom_tile(aes(fill = prop_arr_del)) + scale_fill_gradient(name = "Proportion", low = "white",high = "steelblue") + labs(x = "Carrier", y = "Month") ggplotly(p3) ```