1

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.

  • It is not related to shiny and you did not provide a reproducible example. Maybe you could look for Customising the Clustered Markers in https://github.com/Leaflet/Leaflet.markercluster – MLavoie Apr 26 '18 at 10:44
  • @MLavoie I have added the UI and server code in full now. Have also added some dummy data which will hopefully help, though the clustering will be different to mine. Had already had a look at that link before asking the quesiton on here, unfortunately I couldn't find anything useful. – adamjhodgson Apr 26 '18 at 11:02

0 Answers0