Load the approriate packages and data
library(nycflights13)
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.4.0 ✔ purrr 1.0.1
## ✔ tibble 3.1.8 ✔ dplyr 1.1.0
## ✔ tidyr 1.3.0 ✔ stringr 1.5.0
## ✔ readr 2.1.3 ✔ forcats 1.0.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
Merge the data sets weather and flights
flightsw <- dplyr::full_join(weather, flights, by = c("year", "month", "day", "hour", "origin"))
## Warning in dplyr::full_join(weather, flights, by = c("year", "month", "day", : Each row in `x` is expected to match at most 1 row in `y`.
## ℹ Row 5 of `x` matches multiple rows.
## ℹ If multiple matches are expected, set `multiple = "all"` to silence this
## warning.
Create a scatterplot with the merged data
ggplot(data = flightsw, aes(x = visib, y = dep_delay, color = origin)) +
geom_point(alpha = 0.5) +
xlab("Visibility") +
ylab("Departure Delay") +
ggtitle("Departure Delay vs Visibility by Origin Airport") +
theme_bw()
## Warning: Removed 16520 rows containing missing values (`geom_point()`).

ggplot(data = flightsw, aes(x = visib, y = arr_delay, color = origin)) +
geom_point(alpha = 0.5) +
xlab("Visibility") +
ylab("Arrival Delay") +
ggtitle("Arrival Delay vs Visibility by Origin Airport") +
theme_bw()
## Warning: Removed 17694 rows containing missing values (`geom_point()`).

The graphs show a scatterplot of arrival delay and departure delay
versus visibility for flights originating from 3 airports. Each point on
the graph represents a flight and is colored according to its origin
airport. The x-axis shows visibility in miles, while the y-axis shows
arrival or departure delay in minutes. The data points are spread out
over the graph, with some flights experiencing significant delays while
others arrive on time. There is a slight negative correlation between
visibility and delay, indicating that flights with better visibility
tend to experience shorter delays.