I want to see the average departure delay in flights dataset from nycflights13 by distance and month with tile plot. I plotted it and I got this:
How can I see it better? I can't understand anything.
Maybe you want something like this. I divide the 'average_delay` in 5 categories so that you get more different colors. You can use this code:
library(nycflights13)
nycflights13::flights
flights %>%
group_by(month) %>%
mutate(average_delay = mean(dep_delay, na.rm=TRUE)) %>%
ggplot(aes(x = distance, y = month)) +
geom_tile(aes(fill = cut_number(average_delay, n = 5))) +
scale_colour_gradientn(colours = terrain.colors(10)) +
scale_fill_discrete(name = "Average delay")
Output:
This is because the
distance
column is continuous. A tile plot needs the two axes to be categorical. So you first need to categorise thedistance
column; one way to do this is withcut_number
fromggplot2
.(A tip: next time you ask a question, it is helpful for us to see the code you have written - otherwise it is more difficult to help you. I needed to check which package the
flights
dataset was from, and what its variables were called).