2016-12-07 43 views
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' 

我知道有我的时间序列列表的问题,但不能了解它是什么。任何帮助表示赞赏。

感谢

回答

0

我有同样的问题用一个单一的TS(双强制),这是用解决。不知道它是否会与你的工作。

用2 ts试一试,只用那些代码运行你的代码。

ts$Value <- as.numeric(as.character(ts$Value)) 

您是否尝试绘制单个ts?