How can I create multiple shades in dygraphs using a data frame?

Nuschka

I have time series data that I plotted using dygraphs. Now I want to shade some events. The start and end points of these events are stored in a data frame. However, when I try to write a function to add multiple shades, I always get error messages.

I have tried using a for loop directly in the code, but then I get the error message that my dummy variable can't be found. I have tried writing a function with a for loop, but somehow when I apply it, the first argument it uses is ".". Which of course messes up the function.

for (i in 1:length(dataframe$start)){
dyShading(from = dataframe$start[i], to = dataframe$end[i])
}
addshading <- function(periods){
  for (i in 1:length(periods[,1])){
    x <-dyShading(from = periods$start[i], to = periods$end[i])
  }
  x
}

Running the for loop directly after dygraph() %>% gives the following error message:

Error in function_list[k] : object 'i' not found

Running addshading(dataframe) directly after dygraph() %>% gives the following error message:

Error in addshading(., dataframe) : unused argument (dataframe)

I hope I made myself clear, I am new to ask for help with coding.

Shree

You need to assign dygraph() to an object first and then incrementally update that object with dyShading() -

p <- dygraph(your_data)

for (i in 1:nrow(dataframe)) {
  p <- p %>% dyShading(from = dataframe$start[i], to = dataframe$end[i])
}

print(p)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how can I create a new data frame using exact rows from the old data frame in R Studio?

How can I create one data frame if I have multiple filters?

How can I create a pandas data frame from each unique combination of multiple lists?

How can I create a data frame in R from a zip file with multiple levels located in an URL?

How can I generate random shades of an RGB?

How can I create a new series by using specific rows and columns of a pandas data frame?

How can I create a multiindex data frame with the following datasets?

How can I create a data frame with all existing variables (at once)?

How can I create a new data frame based on the existing columns?

How can I sort a data frame conditionally by multiple columns in R?

How can I summarize a data frame in a "long" format by multiple columns?

How can I scale points in Dygraphs?

How can I "expand" a data frame of hyphentated addresses using R?

How can I insert values into a data frame dynamically using R

How can I conditionally subset a data frame using a function in R?

How can I create multiple boxplots with seaborn using cuts of data from the same dataframe

How can I keep the rows of a pandas data frame that match a particular condition using value_counts() on multiple columns

How to create a data frame from multiple vectors?

How can I search in a data frame if all possible combinations exist in another data frame in R using dplyr?

How do I create multiple new data frames in R, derived from a single data frame and named sequentially?

How can I create an Item Frequency Plot for association rule data? By converting to data frame or numeric?

R: How can I transfer values from multiple data frames to another data frame depending on certain conditions?

How can I plot and curve fit multiple data sets within one data frame? in R

How can I create multiple button with insertion to textarea using this script

How can I create multiple files using chef recipe?

how can I create a pyspark udf using multiple columns?

How can I create a subset a database using multiple conditions?

Can I create column where each row is a running list in a Pandas data frame using groupby?

How do I create multiple data frames using a for loop in python