NYC Flights Assignment

Author

Sephora Apeti

For this assignment I will be creating a tree map showing the number of flights operated by each airline, the size of each rectangle represents the number of flights.

Loading Packages:

library(nycflights13)
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.2.1     ✔ readr     2.2.0
✔ forcats   1.0.1     ✔ stringr   1.6.0
✔ ggplot2   4.0.3     ✔ tibble    3.3.1
✔ lubridate 1.9.5     ✔ tidyr     1.3.2
✔ purrr     1.2.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(treemapify)

Prepare/Cleaning data:

airline_flights_count <- flights |>
  group_by(carrier) |>
  summarize(
  count = n()
  )

Creating Tree-map:

ggplot(airline_flights_count, aes(area = count, fill = carrier, label = carrier)) +
  geom_treemap() +
  geom_treemap_text() +
  labs(
    title = "Number of Flights by Airline",
    fill = "Airline",
    caption = "Source: NYC Flights data, nycflights13 package"
  )

I did not add x and y axis since I don’t really need one for this graph