Compare data on hover : RStudio graph viewer

Hi folks!

first time question - I’m using RStudio, and have installed the plotly library. With a dataframe I wanted to see how it would show up in the plot view and came up with this:

p <- plot_ly(data_toplot, x = data_toplot$Received, y = data_toplot$Approve, name = 'Approval', type = 'scatter', mode = 'lines') %>%
  add_trace(y = data_toplot$Disapprove, name = 'Disapproval', type = 'scatter', mode = 'lines') %>%
  layout(
title = 'Approval Dates',
xaxis = list(
  title = 'Dates'
),
yaxis = list(
  title = 'Approval'    )
  )

My question , how to set the ‘compare data on hover’ option to be on by default? When the graph show up, I have to click on the button in the viewer to enable this. I’d very much like to get it to display automatically.

1 Like

Hey @robulus

To set the type of hover interactions you can use hovermode in the layout https://plot.ly/r/reference/#layout-hovermode

Could you please give an example ,i can uderstand how to use hovermode to set the ‘compare data on hover’