Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Improving plot readability

I need to look for correlations in the publicly available flights package. I managed to make a scatter plot using ggplot. enter image description here 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?

like image 906
SomeDutchGuy Avatar asked Aug 01 '26 13:08

SomeDutchGuy


1 Answers

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)")

enter image description here

like image 79
Edward Avatar answered Aug 03 '26 04:08

Edward



Donate For Us

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