Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Time Series Plotting using plot_ty

I have some time series data that has gaps and I don’t want to connect the gaps. I know there is the connectgaps attribute in Python but want to know if there is something like that for R. Thanks!

Hi, is this the attribute you were looking for: https://plot.ly/r/reference/#scatter-connectgaps?

Perhaps, some code would help.

library(xts)
library(plotly)

x <- xts(
  c(runif(10,0,1), NA, NA, runif(10,0,1)),
  order.by = seq.Date(Sys.Date(), by="days", length.out=22)
)

plot(x)

plot_ly(
  data = data.frame(date=index(x), value=x[,1,drop=T]),
  x = date,
  y = value
)

plot_ly(
  data = data.frame(date=index(x), value=x[,1,drop=T]),
  x = date,
  y = value,
  connectgaps = TRUE
)