对于R,当运行POSIXct时出现错误时,如何确定原点

对于R,当运行POSIXct时出现错误时,如何确定原点,r,posixct,R,Posixct,抛出一个错误,说我没有指定原点-我以为原点是自动的1970-01-01 00:00:00,我不需要指定。在同事编写代码之前,代码是有效的。如何更正此错误?下面是部分代码(如果有帮助的话,我也可以发布完整的脚本) 示例数据csv: 年月、计数、区域、域 2011-04-01 00:00:001786,城市1,区域1 2011-05-01 00:00:001762,城市1,区域1 2011-06-01 00:00:001932,城市1,区域1 错误消息: as.POSIXct.numeric(索引(

抛出一个错误,说我没有指定原点-我以为原点是自动的1970-01-01 00:00:00,我不需要指定。在同事编写代码之前,代码是有效的。如何更正此错误?下面是部分代码(如果有帮助的话,我也可以发布完整的脚本)

示例数据csv:

年月、计数、区域、域

2011-04-01 00:00:001786,城市1,区域1

2011-05-01 00:00:001762,城市1,区域1

2011-06-01 00:00:001932,城市1,区域1

错误消息:

as.POSIXct.numeric(索引(dfplot))中出错:必须提供“origin”

R代码(对于错误红色代码,请转至注释#精确绘制数据):

#绘图
######################################
#合并时间序列并导出数据

没有看到数据样本的dfplot很难提供有意义的答案。对于初学者来说,
索引
函数从何而来?
索引(dfplot)
是否返回数字或字符串?Inputdata是原始数据。R global environment表示Inputdata的数据框有4个字段。第一个字段是YEARMONTH:chr“2011-04-01 00:00:00”。所以索引最初是一个字符串。然后,Inputdata成为InputDataTimeSeries。从代码来看,InputDataTimeSeries是dfplot的组成部分。但奇怪的是,我无法在全局环境中看到InputDataTimeSeries。我在这里遗漏了什么?我不认为这是一个使用
index
函数的正确应用程序。只需尝试使用
ggplot(dfplot,aes(x=as.POSIXct(YEARMONTH))
谢谢您的建议。错误现在是:as.POSIXct(YEARMONTH)中的错误:未找到对象“YEARMONTH”。我只是尝试添加原点,结果成功了<代码>ggplot(dfplot,aes(x=as.POSIXct(索引(dfplot),origin=“1970-01-01 00:00.00 UTC”))
。你知道为什么吗?
  # Plot

  ######################################

  #Merge Time Series and Export Data
dfplot <- merge(as.xts(InputDataTimeSeries), as.xts(pred$lower))
dfplot <- merge(dfplot, as.xts(pred$mean))
dfplot <- merge(dfplot, as.xts(pred$upper))
dfplot <- merge(dfplot, as.xts(pred$fitted))

names(dfplot)[1:7] <- c("actuals", "lower80", "lower95", "predicted", "upper80", "upper95", "fitted")

#Nicely Plot the Data
ggplot(dfplot, aes(x=as.POSIXct(index(dfplot)))) +
geom_line(aes(y=fitted), col='grey90', size = 2) +
geom_line(aes(y=predicted), col='orange', size= 1) +
geom_line(aes(y=actuals), col='orange', size= 1) +

geom_ribbon(aes(ymin=lower80,ymax=upper80),alpha=0.3, fill="orange") +
geom_ribbon(aes(ymin=lower95,ymax=upper95),alpha=0.1, fill="orange") +
theme_bw() +
geom_vline(xintercept=as.numeric(as.POSIXct(end(InputDataTimeSeries))), linetype="dashed", fill="gray40") +
labs(title=paste(pred$method, "80/95% PI Bands" ) , x="Time", y="Observed / Fitted") +
theme(plot.title = element_text(size=18, face="bold"))