Black Lives Matter. Please consider donating to Black Girls Code today.
Learn how to use COVID-19 data in open source Dash apps. Register for the Sept 23rd webinar with IQT!

Unexpected output using plotly and geom_tile

I’m trying to print a heatmap using ggplot2's geom_tile and display it using the package plotly, but I get some unexpected behavior.

There is a reproducible example in plotly’s website

To make it easier, I paste the code here:


p <- volcano %>%
  melt() %>% 
  ggplot(aes(Var1, Var2, fill = value)) + geom_tile()

According to the website, I’m supposed to get something like this:

The supposed output according to the website

But the result I get is the next one:

The result I get with plotly

The funny thing is that if I print the ggplot object p with print(p) I get the outcome I was supposed to get:

The result I get with ggplot

which makes me think that the problem is plotly and not ggplot.

I’ve run the code from other examples using ggplot and plotly and it all works perfectly, the issue seems to be with geom_tile.

My SessionInfo() is:

R version 3.2.4 Revised (2016-03-16 r70336)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 15.10

And the versions of ggplot an plotly are:

  • ggplot2: 2.1.0
  • plotly: 3.4.1

I also tested this code with a Mac and got the same unexpected results.

Our documentation needs to be updated to reflect the most recent functionality. The current development version of plotly is 3.4.13 (which you can install with devtools::install_github('ropensci/plotly')), and matches the ggplot2 result.

You’re right. That works, thank you very much.

Also, I noticed that with the released version the following code gets the desired output:

p <- t(volcano) %>%
melt() %>% 
ggplot(aes(x=Var2, y=Var1)) + geom_tile(aes(fill=value))