r - Time Axis Values Incorrect in some ggplot plots but not others -
forum,
this data looks like:
> data.cvg source: local data frame [938 x 5] date day time parameter value (time) (fctr) (time) (chr) (dbl) 1 2016-03-05 01:35:03 sat 2016-03-06 01:35:03 terminalgarageutilization 35.367 2 2016-03-05 01:40:01 sat 2016-03-06 01:40:01 terminalgarageutilization 35.350 3 2016-03-05 01:43:18 sat 2016-03-06 01:43:18 terminalgarageutilization 35.350 4 2016-03-05 01:45:01 sat 2016-03-06 01:45:01 terminalgarageutilization 35.350 5 2016-03-05 01:50:02 sat 2016-03-06 01:50:02 terminalgarageutilization 35.333 .. ... ... ... ... ...
a new datapoint generated every 5 seconds.
if use code, plot correctly prints data values, time axis. notice, @ time of writing post, last datapoint @ mar 7th, 1:50am est, marked red line ('mon').
ggplot(data.cvg)+geom_line(aes(x=time,y=terminalgarageutilization,color=day))
if attempt @ re-formatting x-axis:
ggplot(data.cvg)+geom_line(aes(x=time,y=terminalgarageutilization,color=day)) +scale_x_datetime(date_labels = "%h:%m",date_breaks = '2 hours')
this plot incorrectly labels x-axis 5:00a 5:00a. notice same red line, how it's marked against 5a-7a.
why this?
thanks, rahul
resolved.
the answer include timezone. correct working code:
library(scales) ggplot(data.cvg)+geom_line(aes(x=time,y=terminalgarageutilization,color=day))+ scale_x_datetime(date_breaks = '2 hours',labels = date_format("%h:%m",tz = "est"))
Comments
Post a Comment