I have been working on heatmaps using in ggplot2
, and I am now trying to convert them to ggplotly
to build a shiny
app with them. Everything works (more or less) fine except for the translation of the alpha aesthetic in geom_tile
(same issue if I use geom_raster
). After a full day of googling and reading related answers, I have not found any solution yet.
I have tried with different data and specifications, and so far no luck at all. The problem seems to be specific to heatmaps, as alpha translates well if I use geom_point. Problem is, I really need heatmaps for what I'm doing.
I have produced a reproducible example that shows the issue.
library(ggplot2)
library(plotly)
library(dplyr)
sample<- data.frame(a = 1:10,
b = 11:20,
c = 31:40,
d = rep(c("a", "b"), 5))
plot <- sample%>%
ggplot(aes(x=a, y=b, fill = c, alpha = d))+
geom_raster()
plot
ggplotly(plot)
You'll see the output is quite different. Any ideas or has anyone had a similar issue?
ggplot:
ggplotly: