I am using the dygraphs
package and I would like to add multiple shaded regions using the dyShading
function. I would like not to have to specify manually the shaded region as it is done in the help of the function:
dygraph(nhtemp, main = "New Haven Temperatures") %>%
dyShading(from = "1920-1-1", to = "1930-1-1") %>%
dyShading(from = "1940-1-1", to = "1950-1-1")
But instead, make a loop on the regions. It would look like something like that (that does not work!):
data %>% dygraph() %>%
for( period in ok_periods ) dyShading(from = period$from , to = period$to )
Do you have any ideas? Thanks you very much
For example:
If you have periods in a list:
Using pipe
If you want to use pipe, you could define a new function
and use it in a chain: