Plotly tooltip text doesnt work in r plotly package

I am trying to use plotly r package to show some tooltips and get this error Warning: 'scatter' objects don't have these attributes: 'tooltip'

Here is the code I am using

p <- plot_ly(dt, x = ~fruits, y = ~rank, type = 'scatter', mode = 'markers',
                 tooltip = 'text')

I have updated to the lastest version of plotly. What can I do to fix this.

You have to replace [ tooltip="text" ] with [ hoverinfo="text" ], and you also have to declare the variable [ text=... ], e.g. one of your columns or a custom vector
Here, hoverinfo="text" is optional. If you don't declare it, the tooltip will display the coordinates in addition to the text.

Here a complete example:

library(plotly)

dt <- data.frame(
  fruits=c("apple","lemon","orange"),
  rank=c(1,2,4)
  )

p <- plot_ly(dt, x = ~fruits, y = ~rank,
             type = 'scatter', mode = 'markers',
             text = ~fruits, hoverinfo="text")
p

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.