1

I have a dygraph plot and want to add several event dyLimit lines..but programmatically. The standard syntax in the server.R for this would be:

dygraph(MSFT[, 4], main = "Microsoft Share Price") %>% 
  dySeries("MSFT.Close", label = "MSFT") %>%
  dyLimit(as.numeric(MSFT[1, 4]), color = "red")

So how can I add these dyLimits in a loop?

MichiZH
  • 5,587
  • 12
  • 41
  • 81

1 Answers1

4

You can create a varibale holding the graph and add the dyLimits one by one in a for loop, here's an example (based on this one):

library(dygraphs)
lungDeaths <- cbind(mdeaths, fdeaths)
graph <- dygraph(lungDeaths) 
for (i in 1:5){
  graph <- graph %>% dyLimit(500*i)
}
graph
NicE
  • 21,165
  • 3
  • 51
  • 68