Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How am I supposed to enter the a size-parameter to a colored plot_ly plot?

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:

plot only color

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

plot only size

plot color and size

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?

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading