Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
aushev opened this issue Nov 11, 2020 · 1 comment
Open

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

aushev opened this issue Nov 11, 2020 · 1 comment

Comments

@aushev
Copy link

aushev commented Nov 11, 2020

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()
@BeppoBrem
Copy link

I had the same problem. Converting to a character is only a partial workaround since the order of the levels in an ordered factor is no longer preserved. The bug should be addressed via #2404

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants