在R中绘制x轴上的日期图

问题描述:

我正在尝试以x轴为日期的情节,间隔为1个月,为了清楚起见,旋转日期值。

I am trying to do a plot with date on x-axis with an interval of 1 month and date values rotated for clarity.

r=runif(100)
d <- as.Date("2001/1/1") + 70*sort(r)
plot(d,r,type="l",xaxt="n")
axis.Date(1, at=seq(d[1],d[100],"month"), format="%m/%d/%Y")

这不起作用。我试图得到类似于以下图形的东西:

This doesn't really work. I am trying to get something similar to the following graph:

它完全符合您要求的功能。

It does exactly what you ask the function to do.

三个月,三个小时。

> d[1]
[1] "2001-01-01"
> d[100]
[1] "2001-03-11"

r=runif(100)
d <- as.Date("2001/1/1") + 70*sort(r)
plot(d,r,type="l",xaxt="n")
axis.Date(1, at = seq(d[1], d[100], length.out=25),
        labels = seq(d[1], d[100], length.out=25),
        format= "%m/%d/%Y", las = 2)

应该很容易地调整为周/月/年。您可以在?par mar 参数播放。

It should be easily adjusted to week/month/year. It's up to you to play with the mar parameter in ?par.