'Editing the limits of the x-axis
I am plotting a graph based on flights delays and time on a 24hour clock. I am using chron and ggplot2 and the x-axis automatically prints from 07:30 to 07:30 when i want it to start from 00:00 to 24:00. Tried changing the (n = ) but that doesnt help. Could not really find any solutions else where therefore any help is greatly appreciated!

library(ggplot2)
library(chron)
#get data from sql
q1c <- dbGetQuery(conn, "
SELECT DepTime as Time,(DepDelay + ArrDelay) AS TotalDelay, AVG(DepDelay + ArrDelay) AS AVGDelay
FROM Ontime
WHERE Cancelled=0 AND Diverted=0 AND ArrDelay >0 AND DepDelay >0
GROUP BY Time
")
q1c
#changing to a time var
temp <- sprintf("%04d", q1c$Time)
timeq1c <- format(strptime(temp, format="%H%M"), format = "%H:%M:%S")
timelabel<- chron(times= timeq1c)
#plot
ggplot(q1c) + geom_jitter(aes(x = timelabel, y = TotalDelay)) + scale_x_chron(format="%H:%M",n=8)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
