0
嗨我有一個我想繪製的67個時間序列對象的列表,然後將這些圖形保存爲不同名稱的jpeg文件。下面是該列表的預覽:在R中繪製並保存時間序列列表
$ SE_VALUES_IMV_IN :List of 3
..$ 220830 : num [1:84] 0 0 0 0 0 0 0 0 0 0 ...
..$ 22083030: num [1:84] 0 0 0 0 0 0 0 0 0 0 ...
..$ 22083082: num [1:84] 0 0 0 0 0 0 0 0 0 0 ...
..- attr(*, "tsp")= num [1:3] 2010 2010 12
..- attr(*, "class")= chr "ts"
$ SI_VALUES_IMV_EU28_EXTRA :List of 8
..$ 220830 : num [1:84] 235549 117953 163342 214415 248162 ...
..$ 22083011: num [1:84] 8026 0 0 6166 0 ...
..$ 22083030: num [1:84] 0 40 0 0 0 0 0 0 0 0 ...
..$ 22083041: num [1:84] 0 0 0 0 0 0 0 0 0 0 ...
..$ 22083071: num [1:84] 0 0 0 0 55910 ...
..$ 22083079: num [1:84] 0 0 0 0 0 0 0 0 0 0 ...
..$ 22083082: num [1:84] 227523 117913 163342 207068 192252 ...
..$ 22083088: num [1:84] 0 0 0 1181 0 ...
..- attr(*, "tsp")= num [1:3] 2010 2011 12
..- attr(*, "class")= chr "ts"
$ SI_VALUES_IMV_EU28_INTRA :List of 12
..$ 220830 : num [1:84] 218674 255317 327377 363219 335267 ...
..$ 22083011: num [1:84] 9363 10129 19672 20631 10403 ...
..$ 22083019: num [1:84] 0 1978 0 0 7116 ...
..$ 22083030: num [1:84] 3837 15684 14588 20487 30870 ...
..$ 22083041: num [1:84] 18979 5123 7176 36842 9390 ...
..$ 22083049: num [1:84] 688 0 0 0 0 0 0 0 0 0 ...
..$ 22083061: num [1:84] 0 0 3452 4225 96 ...
..$ 22083069: num [1:84] 0 0 0 40 0 0 7520 0 0 0 ...
..$ 22083071: num [1:84] 139915 204803 256095 218105 185088 ...
..$ 22083079: num [1:84] 0 3219 0 0 3381 ...
..$ 22083082: num [1:84] 45892 14381 26394 62889 88527 ...
..$ 22083088: num [1:84] 0 0 0 0 396 0 0 0 642 105 ...
..- attr(*, "tsp")= num [1:3] 2010 2011 12
..- attr(*, "class")= chr "ts"
所以我已經通過應用lapply()
到我的清單寫一個函數來繪製(使用ts.plot()
)以下元素:
fun2 <- function(x){
mypath <- file.path("C:","Users","Documents", "FI-R", "graphs", paste("multiplot-", x ,".jpeg", sep = ""))
jpeg(file=mypath, width = 10, height = 10, units = 'in', res = 400)
ts.plot(x, col = 1:ncol(x), ylab="Import Value", main=deparse(substitute(x)))
legend("topleft", colnames(x), col = 1:ncol(x), lty = 1)
dev.off()}
Plot.Ts.whisk.lst <- lapply(Ts.whisk.lst.2, fun2)
這當然是不工作的,但它顯示了我的野心。我試圖簡化問題,只是運行的代碼如下:
Plot.Ts.whisk.lst <- lapply(Ts.whisk.lst.2, function(x) ts.plot(x))
但我得到的錯誤:
Error in xy.coords(x, NULL, log = log) :
(list) object cannot be coerced to type 'double'
我知道有我的時間序列列表的問題,但不能瞭解它是什麼。任何幫助表示讚賞。
感謝