Summarizing the data

summary(flights)
##       year          month             day           dep_time    sched_dep_time
##  Min.   :2013   Min.   : 1.000   Min.   : 1.00   Min.   :   1   Min.   : 106  
##  1st Qu.:2013   1st Qu.: 4.000   1st Qu.: 8.00   1st Qu.: 907   1st Qu.: 906  
##  Median :2013   Median : 7.000   Median :16.00   Median :1401   Median :1359  
##  Mean   :2013   Mean   : 6.549   Mean   :15.71   Mean   :1349   Mean   :1344  
##  3rd Qu.:2013   3rd Qu.:10.000   3rd Qu.:23.00   3rd Qu.:1744   3rd Qu.:1729  
##  Max.   :2013   Max.   :12.000   Max.   :31.00   Max.   :2400   Max.   :2359  
##                                                  NA's   :8255                 
##    dep_delay          arr_time    sched_arr_time   arr_delay       
##  Min.   : -43.00   Min.   :   1   Min.   :   1   Min.   : -86.000  
##  1st Qu.:  -5.00   1st Qu.:1104   1st Qu.:1124   1st Qu.: -17.000  
##  Median :  -2.00   Median :1535   Median :1556   Median :  -5.000  
##  Mean   :  12.64   Mean   :1502   Mean   :1536   Mean   :   6.895  
##  3rd Qu.:  11.00   3rd Qu.:1940   3rd Qu.:1945   3rd Qu.:  14.000  
##  Max.   :1301.00   Max.   :2400   Max.   :2359   Max.   :1272.000  
##  NA's   :8255      NA's   :8713                  NA's   :9430      
##    carrier              flight       tailnum             origin         
##  Length:336776      Min.   :   1   Length:336776      Length:336776     
##  Class :character   1st Qu.: 553   Class :character   Class :character  
##  Mode  :character   Median :1496   Mode  :character   Mode  :character  
##                     Mean   :1972                                        
##                     3rd Qu.:3465                                        
##                     Max.   :8500                                        
##                                                                         
##      dest              air_time        distance         hour      
##  Length:336776      Min.   : 20.0   Min.   :  17   Min.   : 1.00  
##  Class :character   1st Qu.: 82.0   1st Qu.: 502   1st Qu.: 9.00  
##  Mode  :character   Median :129.0   Median : 872   Median :13.00  
##                     Mean   :150.7   Mean   :1040   Mean   :13.18  
##                     3rd Qu.:192.0   3rd Qu.:1389   3rd Qu.:17.00  
##                     Max.   :695.0   Max.   :4983   Max.   :23.00  
##                     NA's   :9430                                  
##      minute        time_hour                     
##  Min.   : 0.00   Min.   :2013-01-01 05:00:00.00  
##  1st Qu.: 8.00   1st Qu.:2013-04-04 13:00:00.00  
##  Median :29.00   Median :2013-07-03 10:00:00.00  
##  Mean   :26.23   Mean   :2013-07-03 05:22:54.64  
##  3rd Qu.:44.00   3rd Qu.:2013-10-01 07:00:00.00  
##  Max.   :59.00   Max.   :2013-12-31 23:00:00.00  
## 

Summarizing total distance and airtime

flights |>
  group_by(carrier) |>
  summarize(total_dist=sum(distance, na.rm=T), total_air=sum(air_time, na.rm = T) ) |>
  arrange(desc(total_dist)) |>
  ungroup()
## # A tibble: 16 × 3
##    carrier total_dist total_air
##    <chr>        <dbl>     <dbl>
##  1 UA        89705524  12237728
##  2 DL        59507317   8277661
##  3 B6        58384137   8170975
##  4 AA        43864584   6032306
##  5 EV        30498951   4603614
##  6 MQ        15033955   2282880
##  7 VX        12902327   1724104
##  8 WN        12229203   1780402
##  9 US        11365778   1756507
## 10 9E         9788152   1500801
## 11 FL         2167344    321132
## 12 AS         1715028    230863
## 13 HA         1704186    213096
## 14 F9         1109700    156357
## 15 YV          225395     35763
## 16 OO           16026      2421

Visualizing Air time and distance flown by airlines

treemap(flights,
        index= "carrier", 
        vSize = "distance", 
        vColor="air_time", 
        type="manual", 
        palette = "RdYlBu",
        title = "Air time and Distance Flown by Airlines",
        title.legend = "Distance Flown")

Calculating average departure delay from each airport by month

delay<-flights |>
  group_by(origin, month) |>
  summarize(avg_delay=mean(dep_delay, na.rm=T))
## `summarise()` has grouped output by 'origin'. You can override using the
## `.groups` argument.
delay
## # A tibble: 36 × 3
## # Groups:   origin [3]
##    origin month avg_delay
##    <chr>  <int>     <dbl>
##  1 EWR        1     14.9 
##  2 EWR        2     13.1 
##  3 EWR        3     18.1 
##  4 EWR        4     17.4 
##  5 EWR        5     15.4 
##  6 EWR        6     22.5 
##  7 EWR        7     22.0 
##  8 EWR        8     13.5 
##  9 EWR        9      7.29
## 10 EWR       10      8.64
## # … with 26 more rows

Plot #2: Departure Delays by Month for New York Airports

ggplot(delay,
       aes(month, avg_delay, color = origin)) +
  geom_point(size = 2, alpha=.5) +
  geom_smooth(se=F, alpha=.5 )+
  scale_color_brewer(palette="Dark2")+
  labs(x="Month", y="Average Departure Delay (Minutes)", title = "Average Departure Delays Per Month\nJanuary 2013 - December 2013", color="Departure Airport")+
  scale_x_discrete(limits=month.abb)+
  theme_minimal()+
  theme(legend.position="bottom")
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'

This assignment explores two different visualiztions of the NYCflights13 dataset. The first plot is a treemap showing the total distance flown and airtime for each of airline flying out of the 3 New York-based airports in 2013. The size of each box represents the total airtime, while the color of the box represents the total distance flown. In terms of distance and airtime, the top five airlines are UA, DL, B6, AA, and EV. The second plot is a scatterplot that visualizes average departure delays from the New York-based airports by month. The best fit lines for each airport appear to highlight some of the travel patterns and seasonality of travel from New York. Departure delays are highest in June, July, and December. It would be interesting to compare this dataset with data about the numbers of people traveling out of these airports each month as well as the weather pattern data. This could provide some information about whether the increased delays are due to more people traveling through these airports because of summer holiday and winter holiday travel or due to weather conditions such as storms in the summer or snow/ice in the winter.