簡體   English   中英

在R中用x軸繪制日期圖

[英]plotting a graph with date on the x-axis in R

我試圖在x軸上做一個帶有日期的圖,間隔為1個月,為了清晰起見,旋轉了日期值。

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

這不起作用。 我想嘗試類似下圖:

參考圖

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

三個月,三個蜱蟲。

> 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參數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM