I have a histogram and I'd like the tooltip to show the percent of observations in that bin.
Here's a simple (reproducible) histogram:
library(tidyverse)
library(ggplot2)
library(plotly)
hist <- iris %>%
ggplot(aes(x = Sepal.Length)) +
geom_histogram(bins = 20)
hist %>%
ggplotly(
# This gives hoverover the count and the variable, but I'd like it
# to also have the percent of total observations contained in that bin
tooltip=c("count", "Sepal.Length")
)
Along with "count" and "Sepal.Length", I'd like to also show the percent of the total number of observations in the tooltip.
For example, the left-most bin (which contains 4 observations), should have a value of 2.7% (4/150)