plotly / plotly.R

An interactive graphing library for R
https://plotly-r.com
Other
2.55k stars 625 forks source link

Monochrome Heatmap + plotly removes the heatmap color #1295

Open RamRS opened 6 years ago

RamRS commented 6 years ago

Hello, I had previously described an issue I faced with heatmaply here: https://stackoverflow.com/questions/50976183/heatmaply-color-when-all-elements-are-the-same-value, and one of the answers pointed out the fact that this was a plotly bug, not a heatmaply bug.

Essentially, when a heatmap for a matrix where all the values are the same (so a monochrome heatmap) is passed to ggplotly, the resulting plotly plot removes the color and renders it all in gray.

library(ggplot2)
library(plotly)
#> 
#> Attaching package: 'plotly'
#> The following object is masked from 'package:ggplot2':
#> 
#>     last_plot
#> The following object is masked from 'package:stats':
#> 
#>     filter
#> The following object is masked from 'package:graphics':
#> 
#>     layout
library(viridis)
#> Loading required package: viridisLite
x <- rep(1, 10)
g <- ggplot(data.frame(x), aes(x=x, y=x, fill=x)) + 
    geom_tile() + 
    scale_fill_viridis(limits = c(0, 1))
g

Created on 2018-06-29 by the reprex package (v0.2.0.9000).

When ggplotly(g) is run, the output is as follows:

I tried attaching this to the reprex but could not, as reprex does not seem to play well with plotly objects, or I am missing something

As you can see, plotly removes the coloring in the heatmap. What is the problem here?

alanocallaghan commented 6 years ago

https://github.com/ropensci/plotly/issues/907

engineerchange commented 3 years ago

Any advice on working around this issue or where in the plotly codebase the root cause may be?