In plotly::plot_ly, it is possible to adjust size for each point and also to color points according to the category they belong to. Let me state how it is done:
library(plotly)
pd <- data.frame(x=1:4, y=1:4, color=c("a", "b", "a", "b"), size=5*(1:4))
plot_ly(pd, x=~x, y=~y, color=~color)
plot_ly(pd, x=~x, y=~y, marker = list(size=~size))
plot_ly(pd, x=~x, y=~y, color=~color, marker = list(size=~size))
You get the following results:
You see that seperately they work fine but combined the plotted result is wrong (the size is not correct). You can also see that the points in the legend are not the same size. Is there a way to solve these problems?
I believe that the wrong plotting is a bug, am I correct?
You can use the size
argument without wrapped in the marker
option like this:
library(plotly)
pd <- data.frame(x=1:4, y=1:4, color=c("a", "b", "a", "b"), size=5*(1:4))
plot_ly(pd, x=~x, y=~y, color=~color, size = ~size)
Created on 2024-04-26 with reprex v2.1.0