#install.packages(c("maps", "mapproj"))
library(tidyverse)
library(xtable)
library(nycflights23)
In-class exercise ggplot2
In [1]:
Instructions
Data set
Recall the nycflights23 package, which provides the following data frames (tibbles):
airlines
airports
flights
planes
weather
Plots
Create plots with ggplot2 for the following prompts/questions.
- How many flights took place each hour, broken down by origin airport and month?
- What carrier has the largest proportion of cancelled flights?
- For the top-3 carriers (total number of flights) across all 3 origin airports in the summer (July-September), show the relationship between departure and arrival delay (use color coding and faceting where appropriate).
- For the top-10 destinations across all 3 origin airports, add a circle (or bubble) to the map. Make the circle size proportionate to the total number of flights to that destination. (Use color coding where appropriate).
ggplot(map_data("state"), aes(long, lat, group=group)) +
geom_polygon(fill="white", color="black") +
theme_bw()
- Create a plot of your own choice and design. (Please state the question your plot is trying to answer.)