I'd like to round the values in the tooltip for ggplotly.
I have code and when you hover over a column, it shows the full value.
I checked the docs but I had a hard time finding instructions.
This is my code
library(fpp)
library(plotly)
library(tidyverse)
gg <-
credit %>%
ggplot(aes(score)) +
geom_histogram(fill = "lightblue") +
theme_ipsum_rc(grid = "XY") +
labs(title = paste0("Histogram: "),
x = "")
ggplotly(gg)
When I hover over one of the columns, it shows the value as the full number (60.2312).
I'd like to show the rounded version of that, so it shows 60 instead
This could be achieved by mapping a formatted string on the
text
aesthetic, e.g. to show thescore
with no digits you could usepaste("score:", scales::number(score, accuracy = 1))
. As this adds another entry in the tooltip you have to add optiontooltip = list("text", "count")
to prevent the default entry forscore
: