plotly.R
plotly.R copied to clipboard
When calling on geom_area tooltip activates when hovering over line, not area
Calling ggplotly
on ggplot
invoking geom_area
results in a plot in which the tooltip activates when hovering over the "lines" separating the areas. I would have expected the tooltip to activate when hovered over the filled
area.
Here is some reprex
library("ggplot2")
library("plotly")
#create the data
data <- data.frame('year' = rep(1981:2020, 2),
"type" = rep(c("a", "b"), 40),
"value" = runif(80))
#Generate the plot
ggplotly(
ggplot(data,
aes(x = year, y = value, fill = type)) +
geom_area(col = "grey", size = 0.5) #set the line col so that you can see the activation when close to the line
)
I don't see any open or closed issues on this. Online, I only see this solution: https://stackoverflow.com/questions/47331323/ggplotly-and-geom-area-display-informations-when-hovering-over-an-area-not-a, which seems convoluted.
Regardless of that solution, I would still assume the expected behavior for geom_area
is for the tooltip to activate over the area, not the line.