Shiny Map Legend not reading "labels" argument

I'm mapping locations of our company's members. We have 2 columns: one is a text field with a revenue band (e.g. $500K-1M) called "Annual_Revenue" and the other is called "AR_num" and stores a corresponding numeric average value for the revenue band (e.g. $750K for the example above).

The map uses the the numeric value in AR_num to generate circle markers with a relative radius to the revenue.

THE ISSUE: the legend us showing the numeric value "AR_num" and I need it to display the band "$500K-1M

". When calling the labels argument and referencing the "Annual_Revenue" the map is still referencing "AR-num".

Here's the code below:

subCM_locs$Annual_Revenue_bin <- cut(subCM_locs$AR_num, 
                                     c(0,500000,1000000,5000000, 10000000, 15000000, 20000000, 25000000, 30000000,35000000,Inf), include.lowest = T,
                                     labels = c('< 500000x',
                                                '500000-1000000x',
                                                '1000000-4000000x',
                                                '5000000-9000000x',
                                                '10000000-14000000x',
                                                '15000000-19000000x',
                                                '20000000-24000000x',
                                                '25000000-29000000x',
                                                '30000000-34000000x',
                                                '35000000-100000000x'))

# define color palette for data markers
library(colorspace)
markerCol <- colorFactor(palette = (diverge_hsv(10)), subCM_locs$AR_num)
#markerCol <- colorFactor(palette = (heat_hcl(10,h=c(0,-100),l=c(75,40),c=c(40,80), power=1)), subCM_locs$AR_num)
server<- function(input, output, session){
  output$membermap<-renderLeaflet({
    leaflet() %>%
      addTiles() %>%
      addProviderTiles(providers$OpenStreetMap, group = 'Open SM')  %>%
      addProviderTiles(providers$OpenStreetMap, group = 'Open SM')  %>%
      #  addProviderTiles(providers$Stamen.Toner, group = 'Toner')  %>%
      addProviderTiles(providers$Esri.NatGeoWorldMap, group = 'Open SM') %>%
      setView(lng = -114.6684, lat = 36.55715, zoom = 7) %>%
      
      addCircleMarkers(data = subCM_locs, lat = subCM_locs$lat, lng = subCM_locs$lon,
                       color = markerCol(subCM_locs$AR_num), 
                       popup = paste("<b>Company: </b>", subCM_locs$Company, "<br>",
                                     "<b>Membership Type: </b>", subCM_locs$"Membership Type", "<br>",
                                     "<b>Annual Revenue: </b>", subCM_locs$Annual_Revenue, "<br>",
                                     "<b>Physical Street: </b>",  subCM_locs$"Street Address", "<br>",
                                     "<b>Physical City: </b>", subCM_locs$City, "<br>",
                                     "<b>Lat/Lng: </b>", subCM_locs$lat, " , ",subCM_locs$lon),
                       radius = ~sqrt(subCM_locs$AR_num*.00001)) %>%
      addLegend(position = 'bottomleft', #position of legend
                pal = markerCol, 
                title = 'Annual Revenue Bin Ranges',
                values = subCM_locs$AR_num, 
                labFormat = labelFormat(prefix = "$"), 
                na.label = "Missing Revenue Info",
                labels = subCM_locs$Annual_Revenue,
                opacity = .75)
    
  })
}

It seems you may want to instead be doing?

markerCol <- colorFactor(palette = (diverge_hsv(10)), subCM_locs$Annual_Revenue_bin)

If not, it would be helpful to have access to subCM_loc to help solve the issue.

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.