0

I have a data.frame with (n) as to show on the y-Axis and for the x-Axis a date with date and time. It's a chr ("2017-01-01 00:00"). It's 24 rows per day with every hour.

> HourLogins
          date hour    n            datehour  nr           datehour2
1   2017-10-01    0  767  2017-10-01 0:00:00   1  2017-10-01 0:00:00
2   2017-10-01    1  459  2017-10-01 1:00:00   2  2017-10-01 1:00:00
3   2017-10-01    2  310  2017-10-01 2:00:00   3  2017-10-01 2:00:00
4   2017-10-01    3  234  2017-10-01 3:00:00   4  2017-10-01 3:00:00
5   2017-10-01    4  180  2017-10-01 4:00:00   5  2017-10-01 4:00:00
6   2017-10-01    5  207  2017-10-01 5:00:00   6  2017-10-01 5:00:00
7   2017-10-01    6  280  2017-10-01 6:00:00   7  2017-10-01 6:00:00
8   2017-10-01    7  631  2017-10-01 7:00:00   8  2017-10-01 7:00:00
9   2017-10-01    8 1254  2017-10-01 8:00:00   9  2017-10-01 8:00:00
10  2017-10-01    9 1683  2017-10-01 9:00:00  10  2017-10-01 9:00:00

I'm doing now the follwing plot:

ggplot(data = HourLogins, aes(x = datehour2, y = n)) +
  geom_line(size = 0.8, linetype = "dashed") +
  geom_point(size = 2.0)

What comes out is basically fine. But because the data.frame does contain like 300 rows, one can't see the axis-Labels because there is not enough space. I'm triying now to plot just one value per day. Like '2017-01-01 00:00'. I just don't know how to do that.

Thanks for your help in advance!

Daniel

gebizzle
  • 51
  • 1
  • 2
  • Possible duplicate of [Formatting dates with scale\_x\_date in ggplot2](https://stackoverflow.com/questions/10576095/formatting-dates-with-scale-x-date-in-ggplot2) – Jan Boyer Nov 01 '17 at 18:11
  • It is best to convert the date/time column from a character string to a POSIXct object. R will then be able to plot the axis like a number instead of 300 separate lables. See `?as.POSIXct` for more guidance. – Dave2e Nov 01 '17 at 18:49

1 Answers1

0

Use the breaks argument in scale_x_date() (see here for more). You could also try a slightly more manual approach than you might like (see this for more).

JepsonNomad
  • 187
  • 2
  • 15