在R中绘制x轴上的日期图 [英] plotting a graph with date on the x-axis in R
本文介绍了在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
.
这篇关于在R中绘制x轴上的日期图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文