plotly / plotly/plotly.R

pie chart color mapping doesn't work properly when aggregating data

Open
#2,468 0 comments 0 reactions 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

This seems to be maybe a partial regression related to #1375. Using similar code to that issue:

library(plotly)
plot_ly(mtcars[c(1,3,5), c("cyl", "drat")], labels = ~cyl, values = ~drat, type = 'pie', 
        marker = list(colors = c("cyan", "magenta", "black"))) %>%
    layout(xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
           yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
Image
plot_ly(mtcars[, c("cyl", "drat")], labels = ~cyl, values = ~drat, type = 'pie', 
        marker = list(colors = c("cyan", "magenta", "black"))) %>%
    layout(xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
           yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
Image

It seems to apply the default palette color to the first group.

Interestingly, if you bang it in there a few more times it shows (though with different order).

plot_ly(mtcars[, c("cyl", "drat")], labels = ~cyl, values = ~drat, type = 'pie', 
        marker = list(colors = c("cyan", "magenta", "black", "magenta", "magenta"))) %>%
    layout(xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
           yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
Image

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 by running the two provided plot_ly examples with mtcars and compare the pie slice colors for aggregated and unaggregated data. Review issue #1375 and trace the color handling for pie charts; done when the supplied colors consistently map to the correct groups without requiring extra color entries.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.