07/10/2021

Code Used to develop graph

Create data

library(plotly)
x <- seq(0,10, length.out = 1000)

aval <- list()
for(step in 1:11){
  aval[[step]] <-list(visible = FALSE,
                      name = paste0('v = ', step),
                      x=x,
                      y=tanh(step*x))
}
aval[3][[1]]$visible = TRUE

create steps and plot all traces

steps <- list()
myFig <- plot_ly()
for (i in 1:11) {
 myFig <- add_lines(myFig,x=aval[i][[1]]$x,  y=aval[i][[1]]$y, 
                  visible = aval[i][[1]]$visible, 
                 name = aval[i][[1]]$name, type = 'scatter', 
                 mode = 'lines', hoverinfo = 'name', 
                 line=list(color='00CED1'), showlegend = FALSE)

  step <- list(args = list('visible', rep(FALSE, length(aval))),
               method = 'restyle')
  step$args[[2]][i] = TRUE  
  steps[[i]] = step 
}  

Add slider control to plot

myFig <- myFig %>%
  layout(sliders = list(list(active = 3,
                             currentvalue = list(prefix = "Frequency: "),
                             steps = steps)))

Tanh Graph

October 05, 2021