plotly bar and line chart
<p>I want to plot a bar together with a line chart in R with plotly.</p>

<p>My first attempt was</p>

<pre><code>p &lt;- plot_ly(
  x = c(1,2,3,4,5),
  y = c(1,2,1.5,3,2),
  type='scatter',
  mode='lines',
  line = list(color = 'black')
)
add_trace(
  p,
  x = c(1,2,3,4,5),
  y = c(0.5,0.7,0.6,0.9,0.8),
  type='bar',
  marker = list(color = 'red')
)
</code></pre>

<p>The result is right, but I get the following warning:</p>

<blockquote>
  <p>Warning message: The following attributes don't exist: 'mode', 'line'</p>
</blockquote>

<p>I guess cause the bar plot in <code>add_trace()</code> cannot handle the <code>line</code> and <code>mode</code> parameter from the <code>plot_ly()</code> function. So I changed the order:</p>

<pre><code>p &lt;- plot_ly(
  x = c(1,2,3,4,5),
  y = c(0.5,0.7,0.6,0.9,0.8),
  type='bar',
  marker = list(color = 'red')
)
add_trace(
  p,
  x = c(1,2,3,4,5),
  y = c(1,2,1.5,3,2),
  type='scatter',
  mode='lines',
  line = list(color = 'black')
)
</code></pre>

<p>This time I get the following message and red markers are displayed on the black line chart.</p>

<blockquote>
  <p>A marker object has been specified, but markers is not in the mode
  Adding markers to the mode...</p>
</blockquote>

<p>How can I fix this? (I'm using the R package <em>plotly 4.1.0</em>)</p>