Shiny - dygraphs: Show all error-bar values in legend

129 Views Asked by At

I am using dygraphs for R and I opened the following issue on GitHub the other day, however, I have not yet received an answer. Therefore, I am hoping someone in here will be able to answer my question.

I want to know if it is possible to show all the values of the prediction interval in the legend, i.e. , lower, actual, upper, without having them as three separate plain dySeries? I like the look of the shading that the upper/lower bars bring, but I would also like to be able to hover over a point and see all the values for that particular point, not just the middle one. If such a function does not exists, is there an easy workaround, maybe with fillGraph = TRUE or something?


library(dygraphs)

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")

The preceding code is the example from the web page, which is similar to my problem. I simply want to see the lwr and upr values in the legend when hovering.

1

There are 1 best solutions below

0
On BEST ANSWER

So I found a workaround for anybody looking for something similar.

library(dygraphs)

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

max <- p[,2]
min <- p[,3]

p <- ts.union(p, max, min)

dygraph(p, main = "Predicted Lung Deaths (UK)") %>%
  dySeries(c("p.lwr", "p.fit", "p.upr"), label = "Deaths") %>%
  dySeries("max", label = "Max", pointSize = 0.01, strokeWidth = 0.001) %>%
  dySeries("min", label = "Max", pointSize = 0.01, strokeWidth = 0.001)

Obviously, this can be modified to suit your needs (e.g. color of the points etc.) The main idea in this method is simply to create two new columns containing the same information that is used in the bands, and then to make the lines to these too small to see.