plotly not creating linear trend line
<p>In creating a trend line for a scatter plot, I am using <code>add_trace</code> to add a linear trend line.</p>

<p>When the data only has one "series" of data, i.e. there is only one group of coordinates, the code below works fine. However, when I introduce a number of series, the "trend line" looks like this:
<a href="https://i.stack.imgur.com/3kRXSm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3kRXSm.png" alt="enter image description here"></a></p>

<p>Here is the relevant part of the code:</p>

<pre><code>    p &lt;- plot_ly(filteredFull(), x=Relative.Time.Progress, y=cumul.ans.keystroke,
                 mode='markers', color=KeystrokeRate, size=KeystrokeRate,
                 marker=list(sizeref=100), type='scatter', 
                           hoverinfo='text', text=paste("token: ",Token, "Keystrokes: ",
                                                          KeystrokeCount)) %&gt;%
        layout(
          xaxis=list(range=c(0,1)),
          yaxis=list(range=c(0,max(filteredFull()$cumul.ans.keystroke)))
        )

     lm.all &lt;- lm(cumul.ans.keystroke ~ Relative.Time.Progress,
              data=df)
      observe(print(summary(lm.all)))
      p &lt;- add_trace(p, y=fitted(lm.all), x=Relative.Time.Progress,
                     mode='lines') %&gt;%
        layout(
          xaxis= list(range = c(0,1))
        )
p
</code></pre>

<p>I can add more code, or try to make a minimal working example, if necessary. However, I'm hoping that this is a famililar problem that is obvious from the code.</p>