Skip to content

Bug: ggplotly ignores colours in ggplot2::scale_fill_gradientn when limits are below the range of the data #606

Open
@talgalili

Description

@talgalili

This is an odd bug (reported first as a heatmaply issue).

If we create a ggplot2 object with colors based on scale_fill_gradientn, then ggplotly respect the colors. But if the limits are set to be within (instead of outside) the range of the data, then ggplotly stops respecting the colors. This may be some fallback for how to deal with NA colors (but I don't know enough about ggplotly to know for sure).

Here is a self contained example:

library(ggplot2)
library(viridis)
library(plotly)
# Equivalent fill scales do the same job for the fill aesthetic
p <- ggplot(faithfuld, aes(waiting, eruptions)) +
  geom_raster(aes(fill = density)) +
  scale_fill_gradientn(colours = viridis(10), limits = c(0.001,.01))
p
ggplotly(p)

Plot in ggplot2:
image

Plot in plotly (see the wrong colors produced!)
image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions