我编写了一个从列表中提取和绘制数据的函数。我想将绘图保存为由两个变量TS和n_PC组合而成的名称。我的代码如下。我该怎么办?
plot_components <- function(WL_1,WL_2,WL_3,WL_4,WL_5,WL_6,WL_7,PC,TS,n_PC) {
TS_comp<- data.frame(reconstructed_ts[[WL_1]][[PC]][[TS]],reconstructed_ts[[WL_2]][[PC]][[TS]],reconstructed_ts[[WL_3]][[PC]][[TS]],reconstructed_ts[[WL_4]][[PC]][[TS]],reconstructed_ts[[WL_5]][[PC]][[TS]],reconstructed_ts[[WL_6]][[PC]][[TS]],reconstructed_ts[[WL_7]][[PC]][[TS]])
names(TS_comp)<-c(as.character(WL_1),as.character(WL_2),as.character(WL_3),as.character(WL_4),as.character(WL_5),as.character(WL_6),as.character(WL_7))
matplot(TS_comp,type="l",xlab="Time",ylab="Reconstructed series",main=as.character(n_PC),lty = "solid")
legend("bottom",
legend = (names(TS_comp)),
col = 1:7,lty = "solid",
text.col = "black",cex = 0.7,
horiz = T,inset = c(0.01, 0.01))
dev.copy(png,'D:/forecast/',file=paste(as.character(TS,n_PC),'.png'))
dev.off()
}
答案 0 :(得分:0)
您需要在粘贴中包含path参数
dev.copy(png, file=paste0('D:/forecast/',as.character(TS,n_PC),'.png'))