Here is a plotly "bubble" map (i.e. a map with markers on it, whose size is mapped to a variable). However, the legend only shows the color categories, but does not show how size relates to value.
library(plotly)
DF = data.frame(
Group = c("A", "B", "A", "B", "A", "C", "C"),
Value = c(100, 80, 90, 150, 120, 60, 110),
lat = c( 40, 32, 36, 44, 31, 39, 37),
long = c(-90, -100, -120, -110, -90, -80,-105))
plot_geo(DF, locationmode = USA-states ) %>%
add_markers(y=~lat, x=~long, color=~Group, size=~Value,
marker=list(sizeref=0.1, sizemode="area")) %>%
layout(geo=list(scope = usa ))
This question shows how to control the size of markers, but does not answer how to show these sizes in the legend. In this and this questions, we can see that if each category has only a single marker size associated with it, then the legend will show markers scaled to the size they are in the bubble plot. But that does not help here. The plotly website has examples of bubble charts and bubble maps, but none of these have a size legend.
Is there a way to add a legend for marker sizes to bubble charts/maps in plotly? The examples above use the R api, but answers using another plotly api (such as python) will also be acceptable.
Edit: Why this is not a duplicate of this question
I had already linked to the question in my original post and explained why it was different. but let me try to explain the difference a little more clearly, since someone has marked it as a possible duplicate anyway...
The linked question relates to someone who was suffering from having the different bubble sizes shown in the legend which happened because they have only one size per category in their data. In contrast, the categories in this example each have bubbles of varying sizes. The OP in the linked question wanted to know how to get rid of the different sizes in the legend - not how to map a value to size in the legend. The answers in the linked question give workarounds of various quality to achieve that. But, in this question I already have a legend in which markers are all the same size. What I want is to add a legend which shows bubbles of a range of sizes each labeled with the value to which that size corresponds. nothing in the linked post asks or shows how to achieve that.