R(week 15)
library(tidyverse) install.packages("nycflights13") library(nycflights13) library(lubridate) dailyFlight <- flights %>% mutate(date = make_date(year, month, day)) %>% group_by(date) %>% summarise(n = n()) dailyFlight2 <- dailyFlight %>% mutate(weekDay = wday(date, label = TRUE, locale = "English")) View(dailyFlight2) ggplot (dailyFlight2, aes(weekDay, n)) + geom_boxplot() dailyFlight2$weekDay <- as.factor(dailyFlight2$weekDay) ggplot(dailyFlight2, aes(x = date, y = n, col = weekDay)) + geom_point() + geom_line() + scale_x_date(NULL, date_breaks = "1 month", date_labels = "%b") delayFlights <- flights %>% group_by(origin, dest) %>% summarise(count = n(), dist = mean(distance, na.rm = TRUE), delay = mean(arr_delay, na.rm = TRUE)) %>% filter(count > 20) ggplot(data = delayFlights) + geom_point(mapping = aes(x = dist, y = delay)) + geom_smooth(mapping = aes(x = dist , y = delay))