Within R Shiny, I have the following code which plots a load of landmarks within the UK in clusters:
Server
server <- function(input,output){
output$mapengland2 <- renderLeaflet({
leaflet(options = leafletOptions(minZoom = 6, maxZoom = 14)) %>%
addTiles() %>%
addCircleMarkers(lng = data$Longitude, lat = data$Latitude, radius = 8,
clusterOptions = markerClusterOptions()))%>%
fitBounds(-4, 48, 4, 58)
})
}
shinyApp(ui=ui, server=server)
UI
ui <- tabsetPanel(
tabPanel("Map",
leafletOutput("mapengland2", width = "100%", height = 800)))
However, I also have a column within my dataset called data$Region
which specifies a region of the UK the landmark is based.
Is there any argument to clusterOptions
or markerClusterOptions
which allows me to cluster the landmarks based on the variable within this column, or do you have to use the default method? I've had a quick look through 'Leaflet for R' on the internet but couldn't find what I was looking for.
Some of the clustering is a bit weird to me - landmarks in Norwich are being grouped with London when I would prefer them to be a separate cluster if possible, just as an example.
Dummy Data
print(data)
Variable Latitude Longitude Region
v1 52.5 1.3 EAST
v2 52.4 1.3 EAST
v3 51.6 0 LOND
v4 51.6 0.1 LOND
v5 51.6 -0.1 LOND
v6 50.6 -1.3 SOUTH
v7 51.6 -2.5 WEST
v8 53.8 -2.4 NORTH
v9 56.4 -1.5 NORTH
v10 55.9 -2.6 NORTH
I am not sure how the default clustering would work for this, but I would want it to cluster the Variable by Region.