假設我有一個格式如下的 excel 檔案(從此
請注意,第一列是年份,第一行是月份。
我嘗試將其轉換為時間序列物件,然后使用ggseasonplotor繪制季節性圖ggplot2。
df <- openxlsx::read.xlsx('dataset1.xlsx', sheet='Sheet1', colNames=TRUE, rowNames = TRUE)
# df <- t(df)
df <- ts(df, start = c(2008, 1), end=c(2021, 12), frequency = 12)
forecast::ggseasonplot(df, col=rainbow(12), year.labels=TRUE)
輸出:
Error in data.frame(y = as.numeric(x), year = trunc(round(time(x), 8)), :
arguments imply differing number of rows: 2352, 168
我怎樣才能使用 R 正確地做到這一點?提前致謝。
參考:

資料
df <- structure(list(month = 1:12, `2008` = c(4466.7095, 3654.5805,
10195.65, 10093.13, 11854.13, 18171.78, 13724.1, 12759.61, 14951.02,
13318.36, 14425.07, 20553.11), `2009` = c(4597.063947, 5678.726053,
13286.21, 13520.3, 16438.02, 24578.03, 17833.66, 17052.78, 20191.81,
17533.16, 17924.44, 25504.42), `2010` = c(7034.610811, 5979.419189,
16778.65, 16950.07, 20615.55, 30689.08, 21818.87, 21131.49, 24871.84,
21686.52, 23141.76, 30717.07)), class = "data.frame", row.names = c(NA,
-12L))
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/449399.html
下一篇:行內R回傳0而不是正確的值?
