Skip to content

Continuous color causes error when x or y is factor #1883

@aushev

Description

@aushev

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions