#'@title Visualization of flights mean delay
#'@description Visualization of the mean delay of flights for different airports.
#'@import ggplot2 dplyr nycflights13 caret mlbench leaps
#'@importFrom methods new
#'@export
# airports -> faa == flights -> dest
# latitude x achse airports -> lat
# longitude y achse airports -> lon
# delay flights -> arr_delay
visualize_airport_delays <- function(){
dest <- arr_delay <- lat <- lon <- NULL
flights <- nycflights13::flights
airports <- nycflights13::airports
datafr_delay <- flights %>%
group_by(dest) %>%
summarise(mean_delay = mean(arr_delay, na.rm=TRUE))
datafr_joined_one <- dplyr::inner_join(flights, airports, by = c("dest" = "faa"))
datafr_one <- dplyr::distinct(dplyr::arrange((dplyr::select(datafr_joined_one, dest, lat, lon)), dest))
datafr_final <- dplyr::inner_join(datafr_delay, datafr_one, by = "dest")
pl <- ggplot(datafr_final, aes(lat, lon)) +
geom_point() +
labs(title = "The mean delay of flights", x = "Latitude", y = "Longitude")
return(pl)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.