# Load the libraries
library(tidyverse)
library(nycflights13)
library(RColorBrewer)NYC Flights Homework
data <- flights# Calculate total flights per month and origin
monthly_flights <- data %>%
group_by(month, origin) %>%
summarize(total_flights = n())# Change the months from numbers to words
monthly_flights$month[monthly_flights$month == 1]<- "January"
monthly_flights$month[monthly_flights$month == 2]<- "February"
monthly_flights$month[monthly_flights$month == 3]<- "March"
monthly_flights$month[monthly_flights$month == 4]<- "April"
monthly_flights$month[monthly_flights$month == 5]<- "May"
monthly_flights$month[monthly_flights$month == 6]<- "June"
monthly_flights$month[monthly_flights$month == 7]<- "July"
monthly_flights$month[monthly_flights$month == 8]<- "August"
monthly_flights$month[monthly_flights$month == 9]<- "September"
monthly_flights$month[monthly_flights$month == 10]<- "October"
monthly_flights$month[monthly_flights$month == 11]<- "November"
monthly_flights$month[monthly_flights$month == 12]<- "December"
# Reorder the months
monthly_flights$month<-factor(monthly_flights$month, levels=c("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"))# Create the bar plot
ggplot(monthly_flights, aes(month, total_flights, fill = origin)) +
geom_bar(stat = "identity", alpha = 0.5, color = "white") +
scale_x_discrete(labels = c("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")) +
scale_fill_manual(values= c("skyblue","salmon","lightgreen"), name = "Airports", labels=c("Newark Liberty","John. F Kennedy","LaGuardia")) +
labs(x = "Months", y = "Total Flights", title = "Total Flights per Month in 2013",
caption = "U.S Bureau of Transportation of Statistics")Summary
This visualization is meant to show the month with the highest number of recorded flights in the year 2013 as collected by the Bureau of Transportation Statistics in the U.S. Each bar represents the total number of flights that departed from an origin airport within each month of 2013. The colors within each bar show a different origin airport. Using this visualization you can observe seasonal patterns in air travel. One interesting aspect about the plot is the variation in flight volumes. There is a disproportionate higher number of flights in July when compared to a month like February.