Similar questions have been asked about changing the colour of the pop-up box when using ggplotly
from the plotly
package, however, none seem to solve my particular issue.
I have a heatmap, created using ggplot
and I'm using ggplotly
to make it interactive. Currently when you hover over a cell in the heatmap, the background colour of the pop-up box is grey. I am trying to make the background colour of the pop-up box to match the colour of the heatmap cell the mouse is hovering over.
To illustrate what I want, the 1st code block below show an example of using geom_point
. When you run the code and hover over a point, the pop-up box is coloured the same as the point.
library(ggplot2)
library(poorly)
p <- ggplot() +
geom_point(data = iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species))
ggplotly(p)
I believe the colour of the pop-up box may be controlled by the color
aesthetic, because when I create a heatmap (like the one below) and have to use fill
, the pop-up box is coloured grey.
library(ggplot2)
library(plotly)
# Dummy data
x <- LETTERS[1:5]
y <- paste0("var", seq(1,5))
data <- expand.grid(X=x, Y=y)
data$Z <- runif(25, 0, 5)
# colour palette
pal <- colorRampPalette(c("darkblue", 'white', 'darkred'))(100)
# Heatmap
p <- ggplot(data, aes(X, Y, fill= Z)) +
geom_tile() + scale_fill_gradientn(colors=pal)
ggplotly(p)
Any suggestions as to how I could get the po-up box background colour to match the colour of the cell it is hovering over in a heatmap?