title: R: Set Plotly hovermode to "compare data on hover"
body: <p>I am trying to create a stacked area chart in R using the Plotly package as part of a Shiny app and would like to compare the data on hover. However, I am hiding the mode bar for design reasons, so I need to declare this option in my code as currently the hover is only shown for the closest data point to the cursor.</p>
  
  <p>However, the <a href="https://plot.ly/r/reference/" rel="noreferrer">Plotly for R reference</a> only gives the options "x" (tooltip on the x-axis), "y" (tooltip on the y axis), "closest" (shows the tooltip for the closest data point to the cursor) and FALSE (disables the tooltip).</p>
  
  <p>Is there a way to do what I would like? Note that this question is pretty much the complete opposite of <a href="https://stackoverflow.com/questions/28439959/hovermode-using-plotly-with-r">this one</a>.</p>
  
  <p>The code I'm using is: </p>
  
  <pre class="lang-r prettyprint-override"><code>plot_ly(data2, 
          x = ~Year,
          y = ~B, 
          name = 'In-centre', 
          type = 'scatter', 
          mode = 'none', 
          fill = 'tozeroy', 
          fillcolor = '#F5FF8D', 
          hoverinfo = 'y') %&gt;%
  add_trace(y = ~A, 
            name = 'At home', 
            fillcolor = '#50CB86', 
            hoverinfo = 'y') %&gt;% 
  layout(xaxis = list(title = "", 
                      showgrid = FALSE, 
                      tickangle = 270, 
                      dtick = 1, 
                      tickfont = list(size = 11)),
         yaxis = list(title = "", 
                      ticklen = 8, 
                      tickcolor = "#EEEEEE", 
                      range = c(-2, 101), 
                      tick0 = 0, 
                      dtick = 10, 
                      tickfont = list(size = 11)),
         showlegend = TRUE,
         legend = list(x = 0, 
                       y = -0.2, 
                       orientation = "h", 
                       traceorder = "normal"),
          margin = list(t = 25, b = 50, r = 10, l = 40)) %&gt;% 
  config(displayModeBar = FALSE)
  </code></pre>
  
  <p>where a (simplified version of) data2 is:</p>
  
  <pre><code>Year   A      B
  2006   18.0   82.0
  2007   19.2   78.3
  2008   17.9   80.2
  2009   20.1   77.7
  </code></pre>