Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 使用绘图在x轴上设置日期_R_Date_Plot_Axis - Fatal编程技术网

R 使用绘图在x轴上设置日期

R 使用绘图在x轴上设置日期,r,date,plot,axis,R,Date,Plot,Axis,我想生成一个在x轴上显示日期的绘图(以R为底) 这是我目前的代码: plot(dr[[ncol(dr)]][-(length(dr[[ncol(dr)]]))], type = 'l', main = paste("Title - ", colnames(dr[ncol(dr)])), xlab = "", ylab = "", xaxt = 'n', col = "red", lwd = 2, cex.main = 2, ylim = c(0,0.5)) title(xlab = "Peri

我想生成一个在x轴上显示日期的绘图(以R为底)

这是我目前的代码:

plot(dr[[ncol(dr)]][-(length(dr[[ncol(dr)]]))], type = 'l', main = 
paste("Title - ", colnames(dr[ncol(dr)])), xlab = "", ylab = "",
xaxt = 'n', col = "red", lwd = 2, cex.main = 2, ylim = c(0,0.5))
title(xlab = "Period", line=0.5, cex.lab = 1.5)
如何将日期放在x轴上

图为:

这是我的可变日期:

 [1] "2008-11-28" "2008-12-31" "2009-01-30" "2009-02-27" "2009-03-31" "2009-04-30" "2009-05-29" "2009-06-30" "2009-07-31"
[10] "2009-08-31" "2009-09-30" "2009-10-30" "2009-11-30" "2009-12-31" "2010-01-29" "2010-02-26" "2010-03-31" "2010-04-30"
[19] "2010-05-31" "2010-06-30" "2010-07-30" "2010-08-31" "2010-09-30" "2010-10-29" "2010-11-30" "2010-12-31" "2011-01-31"
[28] "2011-02-28" "2011-03-31" "2011-04-29" "2011-05-31" "2011-06-30" "2011-07-29" "2011-08-31" "2011-09-30" "2011-10-31"
[37] "2011-11-30" "2011-12-30" "2012-01-31" "2012-02-29" "2012-03-30" "2012-04-30" "2012-05-31" "2012-06-29" "2012-07-31"
[46] "2012-08-31" "2012-09-28" "2012-10-31" "2012-11-30" "2012-12-31" "2013-01-31" "2013-02-28" "2013-03-29" "2013-04-30"
[55] "2013-05-31" "2013-06-28" "2013-07-31" "2013-08-30" "2013-09-30" "2013-10-31" "2013-11-29" "2013-12-31" "2014-01-31"
[64] "2014-02-28" "2014-03-31" "2014-04-30" "2014-05-30" "2014-06-30" "2014-07-31" "2014-08-29" "2014-09-30" "2014-10-31"
[73] "2014-11-28" "2014-12-31" "2015-01-30" "2015-02-27" "2015-03-31" "2015-04-30" "2015-05-29" "2015-06-30" "2015-07-31"
[82] "2015-08-31" "2015-09-30" "2015-10-30" "2015-11-30" "2015-12-31"

由于您错过了
y
变量,我将用变量日期举例说明

data <- as.Date(data, format= "%Y-%m-%d", tz = "UTC", origin="1970-01-01")
ats = seq(1, length(runif(length(data))),2) # this is the position
labs = seq.Date(min(data), max(data), length.out = length(ats)) # these are the labels to plot in the x axis
plot(runif(length(ats)) ~ ats , type = 'l', main =  "Title ", xlab = "", ylab = "",
     xaxt = 'n', col = "red", lwd = 2, cex.main = 2, ylim = c(0,1)) # note here that the values are randomly generated using `runif`. 
axis(1, at = ats, labels = labs, las= 2)

数据请发布一个可复制的示例。除非我们知道x轴值的结构,否则无法真正帮助您。我编辑了我的评论,请修复图像的链接。还有,复习一下。非常感谢你的建议。
data <- c("2008-11-28", "2008-12-31",   "2009-01-30",   "2009-02-27",   "2009-03-31",   "2009-04-30",   "2009-05-29",   "2009-06-30",   "2009-07-31",
"2009-08-31",   "2009-09-30",   "2009-10-30",   "2009-11-30",   "2009-12-31",   "2010-01-29",   "2010-02-26",   "2010-03-31",   "2010-04-30",
"2010-05-31",   "2010-06-30",   "2010-07-30",   "2010-08-31",   "2010-09-30",   "2010-10-29",   "2010-11-30",   "2010-12-31",   "2011-01-31",
"2011-02-28",   "2011-03-31",   "2011-04-29",   "2011-05-31",   "2011-06-30",   "2011-07-29",   "2011-08-31",   "2011-09-30",   "2011-10-31",
"2011-11-30",   "2011-12-30",   "2012-01-31",   "2012-02-29",   "2012-03-30",   "2012-04-30",   "2012-05-31",   "2012-06-29",   "2012-07-31",
"2012-08-31",   "2012-09-28",   "2012-10-31",   "2012-11-30",   "2012-12-31",   "2013-01-31",   "2013-02-28",   "2013-03-29",   "2013-04-30",
"2013-05-31",   "2013-06-28",   "2013-07-31",   "2013-08-30",   "2013-09-30",   "2013-10-31",   "2013-11-29",   "2013-12-31",   "2014-01-31",
"2014-02-28",   "2014-03-31",   "2014-04-30",   "2014-05-30",   "2014-06-30",   "2014-07-31",   "2014-08-29",   "2014-09-30",   "2014-10-31",
"2014-11-28",   "2014-12-31",   "2015-01-30",   "2015-02-27",   "2015-03-31",   "2015-04-30",   "2015-05-29",   "2015-06-30",   "2015-07-31",
"2015-08-31",   "2015-09-30",   "2015-10-30",   "2015-11-30",   "2015-12-31")