7

I am plotting journey time for a series of roads at hourly resolution, with data over a few weeks.

I can plot using unix time, but that isn't very intuitive. This is 7 days worth of data.

enter image description here

I used a function to manipulate the time field in order to give the date and hour:

def plot_time(time):
    return time.strftime('%Y-%m-%d-%H')

However, this results in ggplot throwing a value error when trying to plot:

ValueError: invalid literal for float(): 2016-04-13-00

Is there a simpler means of displaying date and some hour?

Alternatively I could plot unix time with a date scale on the axis but it would be nice to have some hour resolution on the axis.

LearningSlowly
  • 8,641
  • 19
  • 55
  • 78

2 Answers2

3

POSIXct was the key here as bVa said.

ggplot(aes(x=as.POSIXct(epoch_time,origin="1970-01-01"),y=lambda)

Once the epoch time was formated POSIXct, it was possible to use scale_x_datetime()

I settled on:

+ scale_x_datetime(breaks=date_breaks("1 day"))
LearningSlowly
  • 8,641
  • 19
  • 55
  • 78
0

I think scale_date is what you exactly need.

sashadereh
  • 223
  • 1
  • 15