Search code examples
rr-leaflet

How to enter numbers in a Leaflet markers (circles)


I have the following dataframe.

head(branches)
# A tibble: 6 × 4
  population_percentage      Lat     Long        Freq
                  <chr>    <dbl>    <dbl>       <dbl>
1                 0.6 % 41.99575 21.43122 0.005875253
2                 0.6 % 41.99575 21.43122 0.006253363
3                 0.8 % 41.99575 21.43122 0.008405683
4                   1 % 41.98857 21.45733 0.009816326
5                 1.1 % 41.99977 21.42708 0.010528918
6                 1.2 % 42.00731 21.36529 0.011750505

Using leaflet, I plot the map.

leaflet(branches) %>% addTiles() %>%
  addCircles(lng = ~Long, lat = ~Lat, weight = 10, color = "#03F", opacity = 0.5,
             radius = ~sqrt(Freq) * 30, popup = ~ population_percentage    
  )

What I want to do now, is to have inside the bubles (or circles) the opulation_percentage as shown in the example below.

enter image description here


Solution

  • I am not sure what you are looking for, but if you want to group the items and show them with numbers inside the circles you can use clusterOptions = markerClusterOptions() inside addCircles or addCircleMarkers