if (require("zoo", quietly = TRUE)) {
set.seed(1071)
# data generated as shown in the zoo vignette
Z.index <- as.Date(sample(12450:12500, 10))
Z.data <- matrix(rnorm(30), ncol = 3)
colnames(Z.data) <- c("Aa", "Bb", "Cc")
Z <- zoo(Z.data, Z.index)
tidy(Z)
if (require("ggplot2", quietly = TRUE)) {
ggplot(tidy(Z), aes(index, value, color = series)) + geom_line()
ggplot(tidy(Z), aes(index, value)) + geom_line() +
facet_wrap(~ series, ncol = 1)
Zrolled <- rollmean(Z, 5)
ggplot(tidy(Zrolled), aes(index, value, color = series)) + geom_line()
}
}
Run the code above in your browser using DataLab