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.
There are two main approaches to controlling the tooltip text when using ggplotly():
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")
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))
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:
If a future user has the same question, your answer can help them
It will save people from investing time in answering your questions later when you already have the answer.