plot.zoo() 错误:"attempt to replicate an object of type 'closure'"

Error in plot.zoo() : "attempt to replicate an object of type 'closure'"

我正在笔记本电脑上复制 DataCamp 中的代码:

 library(xts) 
 plot.zoo(flights_xts, plot.type = "multiple", ylab = labels)
 plot.zoo(flights_xts, plot.type = "single", lty = lty)
 legend("right", lty = lty, legend = labels)

并且在执行以上三行代码时出现了以下错误:

Error in rep(ylab, length.out = ngraph) : 
attempt to replicate an object of type 'closure'

Error in strwidth(legend, units = "user", cex = cex, font = text.font) : 
cannot coerce type 'closure' to vector of type 'character'

在函数参数中使用引号(“.”)时的错误已修复:

plot.zoo(flights_xts, plot.type = "multiple", ylab = "labels")
plot.zoo(flights_xts, plot.type = "single", lty = "lty")
legend("right", lty = "lty", legend = "labels")

虽然在线 DataCamp.com 环境中不需要这些引号,但仍然很有趣。对此有何评论?

看起来 datacamp.com 个对象 lty 和标签是为此任务预定义的。 对我来说作品:

lty <- c(1, 2, 3, 4)
labels <- c("Total", "Delay", "Cancel", "Divert")