R/visualise_airport_delay.R

Defines functions visualize_airport_delays

Documented in visualize_airport_delays

#' Visualize Airport Delays
#' 
#' This function plots the Mean Delay Time of Flights in USA Airports.
#' The function does not take any parameters.
#' 
#' @return The function returns a graph.
#' 
#' @example visualize_airport_delays()
#' 
#' @import dplyr
#' @import ggplot2
#' @import nycflights13
#' @importFrom stats model.matrix var
#' @export

visualize_airport_delays = function(){
  lon = lat = dest = arr_delay = Mean = name <- NULL
  options(dplyr.summarise.inform = FALSE)
  delay_flights = nycflights13::flights %>%
    group_by(dest) %>%
    summarize(Mean = mean(arr_delay, na.rm = TRUE)) %>%
    left_join(nycflights13::airports, by = c("dest" = "faa")) %>%
    filter(!is.na(name))
  
  plot = ggplot(delay_flights, aes(x = lon, y = lat, color = Mean)) +
    geom_point() + 
    labs(title = "Mean Flight Delays", x = "Longitude", y ="Latitude")
  
  return(plot)
}
shwva184/ridgereg documentation built on Dec. 31, 2020, 5:17 a.m.