UPDATE: Opened as a bug report here: https://github.com/ropensci/plotly/issues/1133
I'm creating a scatter plot with plot_ly
, where color is indicated by a factor variable and size is indicated by a numeric. It appears that the size is oddly affected by the color in this situation.
To demonstrate, here I assign the same variable to both x
and size
. One would expect the largest points to be on the far right in this case. This demo code includes some extra hoverinfo
for debugging.
library(plotly)
my_data <- mtcars
my_data$carb <- as.factor(mtcars$carb)
plot_ly(my_data,
x = ~wt,
y = ~mpg,
size = ~wt,
color = ~carb,
type = 'scatter',
mode = 'markers',
hoverinfo = 'text',
text = ~paste0('wt (x): ', wt, '\n',
'mpg (y): ', mpg, '\n',
'wt (size): ', wt, '\n',
'carb (color): ', carb, '\n'))
Instead of the largest dots being on the right, it appears as though the size is being scaled within each color group, which is not at all what I actually want:
I've tried changing from factor to character and the same thing occurs, and if I change to numeric (to use the factor level to map to color) then the legend becomes continuous, which is no good. Any ideas?