size legend for plotly bubble map/chart

后端 未结 1 896
無奈伤痛
無奈伤痛 2021-01-04 06:32

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 h

相关标签:
1条回答
  • 2021-01-04 07:05

    After seeing a few comments on the question suggesting that this can't be done, I had another go a it myself, and here is one approach that works pretty nicely.

    legend.sizes = seq(80, 160, 20)
    ax = list(zeroline = FALSE, showline = FALSE, showticklabels = FALSE, showgrid = FALSE)
    mk = list(sizeref=0.1, sizemode="area")
    
    p.map = plot_geo(DF, locationmode = 'USA-states') %>%
      add_markers(x = ~long, y = ~lat, color = ~Group, size = ~Value, marker = mk) %>%
      layout(geo = list(scope = 'usa'))
    
    p.legend = plot_ly() %>%
      add_markers(x = 1, y = legend.sizes, size = legend.sizes, showlegend = F, marker = mk) %>%
      layout(xaxis = ax, yaxis = list(showgrid = FALSE))
    
    subplot(p.legend, p.map, widths = c(0.1, 0.9))
    

    0 讨论(0)
提交回复
热议问题