2

予測プロセスから x 軸に日をプロットしたいと思います。ここのガイドを使用して例を作成しました: https://stackoverflow.com/a/10347205/2366057

リンクからの例:

 Lines <- "Date        Used
 2011-11-1/00:00:00   587
 2011-11-2/01:00:00   578
 2011-11-3/02:00:00   600
 2011-11-4/03:00:00   599
 2011-11-5/04:00:00   678
 2011-11-6/05:00:00   555
 2011-11-7/06:00:00   650"

 dm <- read.table(text = Lines, header = TRUE)
 x = dm
require(lubridate)
library(forecast)
 y = ts(x$Used, start=c(2011, yday("2011-11-01")), frequency=365)
 fcast = forecast(ets(y), 10)
 plot(fcast, xaxt="n")
  a3 = strptime(x$Date, "%Y-%m-%d/%H:%M:%S")
 axis(1, at = decimal_date(a3), labels = format(a3, "%Y-%b-%d %H:%M:%S"), cex.axis=0.3, las=2)

私のデータ:

"day","price"
"2010-02-12 00:00:00",12
"2010-02-12 01:00:00",14
"2010-02-12 02:00:00",15
"2010-02-12 03:00:00",14
"2010-02-12 04:00:00",13
"2010-02-12 05:00:00",16

上記のように、データをcsvファイルに入れています。

 df = read.csv(filepath, header=TRUE, sep=",")

 require(lubridate)
 library(forecast)
 y = ts(df$price)
 fcast = forecast(ets(y), 10)

 plot(fcast, xaxt="n")
 a3 = strptime(df$day, "%Y-%m-%d %H:%M:%S")
 axis(1, at = decimal_date(a3), labels = format(a3, "%Y-%b-%d %H:%M:%S"), cex.axis=0.6, las=2)

x 軸の 2 番目のスニペットでは、日は表示されません。何が間違っているのですか?

前もって感謝します。

4

1 に答える 1