``` title: “Airline Reliability Dashboard New York Flights 2013” output: flexdashboard::flex_dashboard: orientation: columns vertical_layout: fill
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)
)
### fct_reorder() is useful for 1d displays the levels:
### flights_delay$carrier, and flights_delay $ prop_dep_del in match the order of the first
### apperarance in data where the factor is mapped to position
flights_delay$carrier <- fct_reorder(flights_delay$carrier, flights_delay$prop_dep_del)
### Get special words so called as the key word "Delay", and gather columns into
### key - value pairs from 5 : 6
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)
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)
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)