简体   繁体   中英

Date x-Axis in R

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

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM