Adding x-axis labels

ggplot2

#1

Hi,

I have a bunch of dates, formatted as:

2018061417
2018061418

It goes, year, month, day, and hour.

When I try to graph it, the x-axis labels go straight from 2018061417, to 2018061516, but it obviously doesn't recognize it as a date (Why would it?).

Is there a way I can manually put in all of the labels I want, or is there another way around it?

Thanks.


#2

You can convert them to datetime objects by using the lubridate::ymd_h() function if they are all in the same format. Then your plot will recognize them as dates and space them properly. If you are using ggplot then you can use scale_x_datetime() to format the labels the way that you want.