plotly / plotly/plotly.R

Continuous color causes error when x or y is factor

Open
#1,883 1 comment 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

When I try to take color from numeric variable and one of the axes is factor, it raises error Error in Summary.factor(...) : ‘range’ not meaningful for factors:

data(mpg)
mpg$classF <- as.factor(mpg$class)

# error when x is factor AND color is numeric:
mpg %>% 
  plot_ly(x = ~classF, y = ~cyl, color = ~displ) %>%
  add_markers()
# Error in Summary.factor(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,  : 
#                             ‘range’ not meaningful for factors

# works fine when x is character:
mpg %>% 
  plot_ly(x = ~class, y = ~cyl, color = ~displ) %>%
  add_markers()

# also works fine if color is factor or character:
mpg %>% 
  plot_ly(x = ~classF, y = ~cyl, color = ~as.character(displ)) %>%
  add_markers()

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 supplied mpg examples in an R session to reproduce the factor-axis and numeric-color failure. Trace the color handling that calls range on factor data; done means the failing example works without error while the character-axis and factor-or-character-color cases continue to work.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.