Errors when animating filled area plot with multiple traces

I’m trying to animate a filled area plot using plotly/R. While my code produces the desired result, plotly prints an error message about ‘scatter’ objects not having the attribute ‘frameOrder’. I’m uncertain if the issue is with the code or a bug in plotly, so I was hoping someone more knowledgeable than me may be able to help.

I have a data frame with a column for time, a column for x coordinates, and two columns for y coordinates named “a” and “b”. I want to plot objects “a” and “b” in a two-dimensional plane and animate them so that they change over time. Here is what I do:

library("plotly")

df <- expand.grid(seq(1:3), seq(1:3), NA, NA)
df <- setNames(df, c("x", "time", "a", "b"))
df$a <- c(1, 0.5, 0.25, 0.5, 1, 0.25, 0.25, 0.5, 1)
df$b <- c(0.25, 0.5, 1, 0.25, 1, 0.5, 1, 0.5, 0.25)

pp <- plot_ly(df, x = ~x)
pp <- add_trace(pp, y = ~df$a, name = "a", frame = ~df$time, type = "scatter", mode = "none", fill = "tozeroy")
pp <- add_trace(pp, y = ~df$b, name = "b", frame = ~df$time, type = "scatter", mode = "none", fill = "tozeroy")
pp

After this runs through, RStudio brings up an interactive plotly plot in the Viewer which looks and works exactly as intended. However, these error messages are printed in the console after I execute ‘pp’:

Warning messages:
1: 'scatter' objects don't have these attributes: 'frameOrder'
Valid attributes include:
'type', 'visible', 'showlegend', 'legendgroup', 'opacity', 'name', 'uid', 'ids', 'customdata', 'selectedpoints', 'hoverinfo', 'hoverlabel', 'stream', 'transforms', 'x', 'x0', 'dx', 'y', 'y0', 'dy', 'stackgroup', 'orientation', 'groupnorm', 'stackgaps', 'text', 'hovertext', 'mode', 'hoveron', 'line', 'connectgaps', 'cliponaxis', 'fill', 'fillcolor', 'marker', 'selected', 'unselected', 'textposition', 'textfont', 'r', 't', 'error_x', 'error_y', 'xcalendar', 'ycalendar', 'xaxis', 'yaxis', 'idssrc', 'customdatasrc', 'hoverinfosrc', 'xsrc', 'ysrc', 'textsrc', 'hovertextsrc', 'textpositionsrc', 'rsrc', 'tsrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
 
2: 'scatter' objects don't have these attributes: 'frameOrder'
Valid attributes include:
'type', 'visible', 'showlegend', 'legendgroup', 'opacity', 'name', 'uid', 'ids', 'customdata', 'selectedpoints', 'hoverinfo', 'hoverlabel', 'stream', 'transforms', 'x', 'x0', 'dx', 'y', 'y0', 'dy', 'stackgroup', 'orientation', 'groupnorm', 'stackgaps', 'text', 'hovertext', 'mode', 'hoveron', 'line', 'connectgaps', 'cliponaxis', 'fill', 'fillcolor', 'marker', 'selected', 'unselected', 'textposition', 'textfont', 'r', 't', 'error_x', 'error_y', 'xcalendar', 'ycalendar', 'xaxis', 'yaxis', 'idssrc', 'customdatasrc', 'hoverinfosrc', 'xsrc', 'ysrc', 'textsrc', 'hovertextsrc', 'textpositionsrc', 'rsrc', 'tsrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'

I think it’s a warning that the data only contains one frame. I get this when I first create my plotly before I add additional frames.

By the way, if you have data=df, you put y=~a. The ~ tells plotly to looks in the “data” object for column a. Or you can just put y=df$a, in which case you don’t need data=df. The latter is actually better IMO.

Thanks for clearing this up. In my case frames are defined by the time column, which I pass to plotly in the call to add_trace(). Is there a way to do this that avoids the warning message?

It’s a good question, as I no longer get this error and I initialise my plot with only a single frame of data. Did you fix the dataframe ~ thing I mentioned? Doesn’t mode=“none” mean that no markers or lines or text are plotted?

Also what does seq(1:3) do? Shouldn’t it be a comma? Did you look at the dataframe?

Yes, I tried calling plotly both with and without the data parameter and ~, but the errors are still present. mode = "lines" plots lines and a filled area, mode = "none" only plots a filled area, but the errors are present in either case. Below is an example that fixes the issue with the seq command and prints the data frame.

library("plotly")

df   <- expand.grid(seq(1, 3), seq(1, 3), NA, NA)
df   <- setNames(df, c("x", "time", "a", "b"))
df$a <- c(1, 0.5, 0.25, 0.5, 1, 0.25, 0.25, 0.5, 1)
df$b <- c(0.25, 0.5, 1, 0.25, 1, 0.5, 1, 0.5, 0.25)
df
#  x time    a    b
#1 1    1 1.00 0.25
#2 2    1 0.50 0.50
#3 3    1 0.25 1.00
#4 1    2 0.50 0.25
#5 2    2 1.00 1.00
#6 3    2 0.25 0.50
#7 1    3 0.25 1.00
#8 2    3 0.50 0.50
#9 3    3 1.00 0.25

pp <- plot_ly()
pp <- add_trace(pp, x = df$x, y = df$a, frame = df$time, name = "a",
                type = "scatter", mode = "none", fill = "tozeroy")
pp <- add_trace(pp, x = df$x, y = df$b, frame = df$time, name = "b",
                type = "scatter", mode = "none", fill = "tozeroy")
pp

Yeah the things I mentioned turned out to be irrelevant, and I haven’t bee able to fix the warning, sorry.

This post shows you how to suppress the warning.