0

I would like to loop through a dataframe and add annotations like

#df.dates is a dataframe with dates in it

for(i in 1:nrow(df.dates))
{
  myDyGraph %>%
  dyAnnotation(df.dates[i], text = "some text here" )
}

When i run this the chart doesn't update?

GeV 126
  • 351
  • 1
  • 3
  • 14
  • 2
    What are you expecting should happen? What should the output look like? Can you provide some sample data or `dput()` `df.dates`? – JasonAizkalns Mar 25 '16 at 12:13
  • right off the bat, there's a problem with the statement in the loop, if df.dates is a data.frame, then it should have a format like `df.dates[x,y]`... not that that's your question – Amit Kohli Mar 25 '16 at 13:37

1 Answers1

1

Create a chart variable, then add the annotations to it with a loop. So your example would become:

myDyGraph <- dygraph(df)

for(i in 1:nrow(df.dates))
{ 
  myDyGraph <- myDyGraph %>% dyAnnotation(df.dates[i], text = "some text here" )
}

myDyGraph

Similar example with DyLimits here

Community
  • 1
  • 1
Ed Wilson
  • 267
  • 3
  • 12