week 5 hw final

Author

Dajana R

## Load the libray and the dataset *** View the dataset
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.4.4     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.0
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(nycflights13)
flights
# A tibble: 336,776 × 19
    year month   day dep_time sched_dep_time dep_delay arr_time sched_arr_time
   <int> <int> <int>    <int>          <int>     <dbl>    <int>          <int>
 1  2013     1     1      517            515         2      830            819
 2  2013     1     1      533            529         4      850            830
 3  2013     1     1      542            540         2      923            850
 4  2013     1     1      544            545        -1     1004           1022
 5  2013     1     1      554            600        -6      812            837
 6  2013     1     1      554            558        -4      740            728
 7  2013     1     1      555            600        -5      913            854
 8  2013     1     1      557            600        -3      709            723
 9  2013     1     1      557            600        -3      838            846
10  2013     1     1      558            600        -2      753            745
# ℹ 336,766 more rows
# ℹ 11 more variables: arr_delay <dbl>, carrier <chr>, flight <int>,
#   tailnum <chr>, origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>,
#   hour <dbl>, minute <dbl>, time_hour <dttm>
data(flights)
head(flights)
# A tibble: 6 × 19
   year month   day dep_time sched_dep_time dep_delay arr_time sched_arr_time
  <int> <int> <int>    <int>          <int>     <dbl>    <int>          <int>
1  2013     1     1      517            515         2      830            819
2  2013     1     1      533            529         4      850            830
3  2013     1     1      542            540         2      923            850
4  2013     1     1      544            545        -1     1004           1022
5  2013     1     1      554            600        -6      812            837
6  2013     1     1      554            558        -4      740            728
# ℹ 11 more variables: arr_delay <dbl>, carrier <chr>, flight <int>,
#   tailnum <chr>, origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>,
#   hour <dbl>, minute <dbl>, time_hour <dttm>
## filter the dataset and remove the missing data 
flights_filtered <- flights |>
  select(carrier,dest,dep_delay) |>
  filter(!is.na(dep_delay), dest == "CLT")

averageDep_delay <- flights_filtered|>
  group_by(carrier)|>
  summarize(averageDep_delay = mean(dep_delay))

## make a bargraph showing the average departure delay by carrier to CLT

plot1 <- ggplot(averageDep_delay, aes(x = carrier, y = averageDep_delay, fill = carrier)) +
  geom_bar(stat = "identity") +
  labs(title = "Average Departure Delay in Flights to CLT by Airlines",
       x = "Airlines", y = "Average Departure Delay in Minutes",
       fill = "Airlines",
       caption = "Data source: nycflights13 Dataset:Flights") +
  theme_minimal() +  scale_fill_manual(values = c("#B7D3DF", "#C9BBCF", "#898AA6", "#957DAD", "#85586F", "#E0BBe4","#5e6472"))


plot1

The visualization shows the average departure delay in flights to Charlotte Douglass International Airport (CLT) by airlines. Each bar represents an airline and the height of each bar shows the average delay, in minutes. The design of the graph uses colors for each airline. One aspect of the graph is the varying delays among airlines with some experiencing longer delays than others. This information can be vital for both travelers and airlines in making decisions about flights, to CLT. ** CHATGPT was used to look/help fix errors and to also make suggestions.