title: R: plotly graph with dual Y axis?
body: <p>I've found this question but answer is not up to date to produce the correct result. </p>
  
  <p><a href="https://stackoverflow.com/questions/39380227/second-y-axis-in-a-r-plotly-graph">Second Y-Axis in a R plotly graph</a></p>
  
  <p>How can I plot a dual y axis plot?</p>
  
  <pre><code>df &lt;- data.frame(MediaDate = as.Date(c("2016-04-01","2016-05-01","2016-06-01"), format = "%Y-%m-%d"),
                   Spend = c(39654, 34446, 27402),
                   Visits = c(19970, 14450, 12419))
  
  
  
  plot_ly(df, x = ~MediaDate, y = ~Spend, type = "bar", name = "Spend") %&gt;%
    add_trace(x = ~MediaDate, y = ~Visits, mode = "lines", yaxis = "y2", name = "Visits") %&gt;%
    layout(yaxis2 = list(overlaying = "y", side = "right"))
  </code></pre>
  
  <p><strong>Produces:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/OKBni.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OKBni.png" alt="enter image description here"></a></p>
  
  <p><strong>What I need (but instead of a bar and a line, 2 lines):</strong></p>
  
  <p><a href="https://i.stack.imgur.com/aUFdd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aUFdd.png" alt="enter image description here"></a></p>