简体   繁体   English

R中的x轴日期

[英]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. 我有一个带有(n)的data.frame,以便在y轴上显示,对于x轴,则显示带有日期和时间的日期。 It's a chr ("2017-01-01 00:00"). 这是一个小时(“ 2017-01-01 00:00”)。 It's 24 rows per day with every hour. 每天每小时24行。

> 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. 但是因为data.frame确实包含300行,所以由于没有足够的空间而看不到axis-Labels。 I'm triying now to plot just one value per day. 我现在正在尝试每天绘制一个值。 Like '2017-01-01 00:00'. 就像“ 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). scale_x_date()使用breaks参数(有关更多信息,请参见此处 )。 You could also try a slightly more manual approach than you might like (see this for more). 您也可以尝试稍微手动方法比你可能会喜欢(看到这个更多)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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