Ggplotly does not follow coordinates given to geom_raster


Hi Plotly community!

I run into unexpected behaviors when using Plotly to produce interactive matrices through the ggplotly function to imitate the results of ggplot2’s geom_raster method.

A simple and reproducible example is as follows:

dataset = data.frame(A = runif(20), B = factor(sample(1:10, 20, replace = T)), C = factor(sample(1:10, 20, replace = T)))
gp = ggplot(dataset, aes(x = B, y = C, fill = A)) + geom_raster()

Here I want to display a matrix showing occurrences of
a factor B against a factor C, and color it by the value A.
The ggplot version of the matrix, as stored in the gp variable, corresponds to what is in the dataset matrix and what I expect. However some points (but not all) are shifted in the plotly version of the matrix, and their position does not correspond to their actual B and C coordinates. This is shown on the next figure, where the tooltip describes a point of coordinates (B = 2, C = 7), present in the dataset, but displayed at the coordinates (B = 3, C = 7).

Is this difference between the ggplot behavior and the ggplotly equivalent a bug or am I missing anything?

Thanks for your help!

PS: I used R 3.4.1, plotly_4.7.1 and ggplot2_2.2.1.9000.


I ended up re-generating my plots with the heatmaply package instead. I still think the behavior I observed is an issue with ggplotly.