我正在笔记本电脑上复制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'
答案 0 :(得分:1)
在函数参数中使用引号("。")时,错误已得到修复:
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
环境中这些引号不是必需的,但它仍然很有趣。对此有何评论?
答案 1 :(得分:0)
似乎为该任务预定义了datacamp.com对象lty和标签。 对我来说有用:
lty <- c(1, 2, 3, 4)
labels <- c("Total", "Delay", "Cancel", "Divert")