Reputation: 2367
I was replicating codes from DataCamp on my laptop:
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)
and was getting the following errors while executing the above three lines of code:
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'
Upvotes: 1
Views: 2082
Reputation: 63
It looks like datacamp.com objects lty and labels are predefined for this task. For me works:
lty <- c(1, 2, 3, 4)
labels <- c("Total", "Delay", "Cancel", "Divert")
Upvotes: 0
Reputation: 2367
The error is fixed when quotes (".") are used in function parameters:
plot.zoo(flights_xts, plot.type = "multiple", ylab = "labels")
plot.zoo(flights_xts, plot.type = "single", lty = "lty")
legend("right", lty = "lty", legend = "labels")
It's still interesting though that in on-line DataCamp.com
environment these quotes were not required. Any comments about that?
Upvotes: 3