Is there way to change hovertext in plotly

I created a graph in ggplot2 which needs to go to a shinydashboard hence I converted it into a plotly graph. But Now it uses some redundant information in the graph as you can see below.

I want to be able to remove some of this information and add some of mine. I tried hoverinfo but it only works in plotly graph created through plotly.

please any complex solution would do. Even if you can point me to a direction to look for would do.

2 Likes

Did you try steps from this link?

1 Like

I did but ggplotly function doesn't have a hoverinfo argument.

It does have ... argument. Can you try passing the required info there?

2 Likes

Thanks for suggestion I tried it but it doesn't work. It doesn't give me any errors though. It simply skips that part.

There must be some way to handle hover info through layout or something...

There are two main approaches to controlling the tooltip text when using ggplotly():

  1. Use the text aesthetic to supply the tooltip text as a character vector, then the tooltip argument in ggplotly() to make sure only this aesthetic is placed in the tooltip
library(plotly)
p <- ggplot(txhousing) + 
  geom_line(aes(date, median, group = city, text = paste0(city, ", TX")))
# by default ggplotly() will display all aesthetic mappings...
# use `tooltip` to specify which ones you want to show
ggplotly(p, tooltip = "text")
  1. Use style() to modify the underlying text attribute directly (warning: this is a more of a hack than a real solution, approach 1 is preferable to this approach).
p <- ggplot(mtcars, aes(wt, mpg)) + geom_point()
style(p, text = row.names(mtcars))

For more info, see https://plotly-r.com/controlling-tooltips.html

9 Likes

Thanks for replying But I already found the solution when I posted it. But Thanks for giving your value-able time in searching this post and replying to it.

@Anantadinath I am glad you found the answer to your question. In the future, if you manage to find an answer to your question before someone posts it, please take a few moments to share the answer here. This has two benefits:

  1. If a future user has the same question, your answer can help them
  2. It will save people from investing time in answering your questions later when you already have the answer.

Thanks!

6 Likes

I do that almost every time I think this one skipped through it.

I will not that for future issues

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