addLayersControl for many variables with multiple categories

I am trying to add many layers to my map where each layer is to give me different information on coverage of workers.
The original layer shows the radius of every worker from certain coordinates.
I used addLayersControl where I had two groups Monday through Friday. (just showing Mon and Tuesday in the below code)
It works great. I can untick and tick the days I want to see coverage for.

Now I want to add additional layers for my other variables. I want to add a layer for state
where I have the 50 states. I also want to add a layer for the customer ( i have 20 customers).
This way I can tick or untick the customers I want to see on a Monday in MI, or have different combinations.

I appreciate any help.

Here is my code:

#Show  days Monday to Friday
coverage_Monday <- coverage_data %>%
  filter(Days == "Monday")
coverage_Tuesday <- coverage_data %>%
  filter(Days == 'Tuesday')

#Create label for Monday cases
coverage_Monday$label <- paste("<p>", coverage_Monday$Inspector.Name, "</p>",
                               "<p>", coverage_Monday$Day, " ", coverage_Monday$Region, "</p>",
                               "<p>", coverage_Monday$City, ", ", coverage_Monday$Postcode, "</p>",
                               "<p>", coverage_Monday$State, "</p>",
                               "<p>", coverage_Monday$Manager, "</p>",
                               "<p>", coverage_Monday$Customer, "</p>",
                               "<p>", coverage_Monday$Inspector.Skill, "</p>",
                               "<p>", coverage_Monday$Days, "</p>",
                               "<p>", coverage_Monday$Radius, "</p>",

#Create label for Tuesday cases
coverage_Tuesday$label <- paste("<p>", coverage_Tuesday$Inspector.Name, "</p>",
                                "<p>", coverage_Tuesday$Day, " ", coverage_Tuesday$Region, "</p>",
                                "<p>", coverage_Tuesday$City, ", ", coverage_Tuesday$Postcode, "</p>",
                                "<p>", coverage_Tuesday$State, "</p>",
                                "<p>", coverage_Tuesday$Manager, "</p>",
                                "<p>", coverage_Tuesday$Customer, "</p>",
                                "<p>", coverage_Tuesday$Inspector.Skill, "</p>",
                                "<p>", coverage_Tuesday$Days, "</p>",
                                "<p>", coverage_Tuesday$Radius, "</p>",

pal <- colorFactor(
  palette = 'Dark2',
  domain = coverage_data$Inpector.Name
#add checkbox control.
scratchmap <- leaflet(coverage_data) %>%
  setView(lng = -95.7129, lat = 34.0902, zoom = 4.499) %>%
  addPolygons(data = shape, fill = NA) %>%
  addProviderTiles(providers$Esri.DeLorme) %>%
  addCircles(lng = coverage_Monday$Longitude,
                   lat = coverage_Monday$Latitude,
                   color = ~pal(coverage_Monday$Inspector.Name),
                   weight = 1,
                   radius = coverage_Monday$radius,
                   opacity = 0.05,
                   label = lapply(coverage_Monday$label, HTML),
                   fillOpacity = 0.05,
                   group = "Monday") %>%
  addCircles(lng = coverage_Tuesday$Longitude,
                   lat = coverage_Tuesday$Latitude,
                   color = ~pal(coverage_Tuesday$Inspector.Name),
                   weight = 1,
                   radius = coverage_Tuesday$radius,
                   opacity = 0.05,
                   fillOpacity = 0.05,
                   label = lapply(coverage_Tuesday$label, HTML),
                   group = "Tuesday") %>%

addLayersControl(overlayGroups = c("Monday", "Tuesday"),
                options = layersControlOptions(collapsed = FALSE),
                 position = 'bottomright')
# addLayersControl(overlayGroups = c("CA","MI"),
#                  options = layersControlOptions(collapsed = FALSE),
#                  position = 'topright')

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