Create a airport map similar to the one above with the color
representing the number of flights per day from NYC to each
airport.
flights2 <- flights %>%
filter(!is.na(dest)) %>%
group_by(dest, month, day) %>%
summarise(flights_count_day = length(dest))
## `summarise()` has grouped output by 'dest', 'month'. You can override using the
## `.groups` argument.
flights3 <- flights2 %>%
group_by(dest) %>%
summarise(avg_flights_day = sum(flights_count_day)/length(dest))
airports %>%
semi_join(flights3, c("faa" = "dest")) %>%
left_join(flights3, c("faa" = "dest")) %>%
ggplot(aes(lon, lat)) +
borders("state") +
geom_point(aes(colour = avg_flights_day)) +
scale_color_gradient(low = "green", high = "red") +
coord_quickmap() +
labs(title = "Flights and Counts from NYC",
x = "Longitude",
y = "Latitude") +
theme(plot.title = element_text(hjust = 0.5, size = rel(1.5)))
## Warning: `borders()` was deprecated in ggplot2 4.0.0.
## ℹ Please use `annotation_borders()` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
