I need to look for correlations in the publicly available flights package. I managed to make a scatter plot using ggplot.
With the code:
library(nycflights13)
attach(flights)
ggplot(flights, aes(x = arr_delay, y = dep_delay)) +
geom_point(size = 2) +
geom_smooth(method="auto", se=TRUE, fullrange=FALSE, level=0.95)
As show in the image most is centered in the bottom left. Is there any way to make this graph look more visually appealing by spreading the plotted values better?
I used facets to separate the flights that arrived early or on time (arr_delay <=0) with those that arrived late (arr_delay>0). The relationship seems different.
library(nycflights13)
library(dplyr)
library(ggplot2)
ff <- flights %>%
filter(!is.na(arr_delay), origin=="LGA") %>% # Filtered to reduce waiting time!
mutate(`Arrival time`=ifelse(arr_delay<=0, "Early", "Delayed"))
ggplot(ff, aes(x = arr_delay, y = dep_delay)) +
geom_point(size = 2, alpha = 0.3) +
geom_smooth(method="auto", fullrange=FALSE, level=0.95) +
facet_wrap(~`Arrival time`, scales="free", labeller=label_both) +
labs(x="Arrival delay (minutes)", y="Departure delay (minutes)")

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With