plotly / plotly/plotly.R

Missing colors in heatmap if values are the identical

Open
#1,926 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
2.7k
Forks
641
PR merge metrics
No merged PRs in 30d

Description

Hello!
when creating a heatmap where values are all the same on a continuous scale, I get the expected colors from ggplot. However, when I put my ggplot into ggplotly, the colors are gone and it's all gray. Only happends, when values are identical. Happens with version 4.9.3 of plotly.

library(ggplot2)
library(dplyr)
library(plotly)

data <- tibble(hour = c(1, 1, 2, 2), day = c(1, 2, 1, 2), evaluation = c(1, 1, 1, 1))
g <- ggplot(data = data, mapping = aes(x = hour, y = day))
g <- g + geom_tile(aes(fill = evaluation), color = "white")
g <- g + scale_fill_gradientn(limits = c(0, 1), colours = c("red", "green"), name = "Availability")

print(g)         # ok, all colors are green as expected
print(ggplotly(g)) # not ok, colors in heatmap are gray, expected to be green

Please let me know if you need more explanation or additional information to track this down.

Thank you and kind regards,
Heiko

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproducible R example in the issue and trace the ggplotly conversion for a continuous heatmap whose evaluation values are identical. Compare the ggplot and ggplotly outputs, then verify that the converted tiles use the expected green color instead of gray.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, r
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.