Reputation: 39174
How to round the hover information when using ggplotly
? In the following example, I created a scatter plot with hover information. I would like to round the numbers in that hover information to integer without changing the actual values.
library(ggplot2)
library(plotly)
p <- ggplot(mtcars, aes(x = wt, y = qsec)) +
geom_point()
ggplotly(p)
Upvotes: 1
Views: 1566
Reputation: 84689
Use the text
aesthetic to do a custom tooltip:
library(ggplot2)
library(plotly)
p <- ggplot(mtcars,
aes(x = wt, y = qsec,
text = paste0("wt: ", round(wt), "</br></br>qsec: ", round(qsec)))) +
geom_point()
ggplotly(p, tooltip = "text")
Upvotes: 4