Skip to content

You can plot error bars (or any other high/low oriented data) along with a series by simply specifying the lower, value, and upper series together in the dySeries() name parameter. For example:

hw <- HoltWinters(ldeaths)
p <- predict(hw, n.ahead = 72, prediction.interval = TRUE)

dygraph(p, main = "Predicted Lung Deaths (UK)") |>
  dySeries(c("lwr", "fit", "upr"), label = "Deaths")

Here’s how you would plot the actual and predicted series on the same graph:

hw <- HoltWinters(ldeaths)
p <- predict(hw, n.ahead = 36, prediction.interval = TRUE)
all <- cbind(ldeaths, p)

dygraph(all, "Deaths from Lung Disease (UK)") |>
  dySeries("ldeaths", label = "Actual") |>
  dySeries(c("p.lwr", "p.fit", "p.upr"), label = "Predicted")

Finally, here’s an example that plots multiple series each of which have upper and lower bars:

library(quantmod)
getSymbols(c("MSFT", "HPQ"), from = "2014-06-01", auto.assign = TRUE)
## [1] "MSFT" "HPQ"
stocks <- cbind(MSFT[, 2:4], HPQ[, 2:4])
dygraph(stocks, main = "Microsoft and HP Share Prices") |>
  dySeries(c("MSFT.Low", "MSFT.Close", "MSFT.High"), label = "MSFT") |>
  dySeries(c("HPQ.Low", "HPQ.Close", "HPQ.High"), label = "HPQ")