Skip to contents

Gambling neighbourhoods using an hybrid approach with HDBSCAN and eps=500m

This vignette demonstrates how to create interactive maps using the leaflet package in R to visualize the gambling neighbourhoods identified using an hybrid approach combining HDBSCAN clustering with a fixed eps=500m. In here we will load the geographical data containing the coordinates of gambling premises and the clustering results from HDBSCAN with eps=500m for different values of MinPts (4,5,10,15,20). We will create a separate map for each value of MinPts, showing the cluster centers and the number of gambling premises in each cluster. Clusters are in blue and represented by polygons, each with a popup displaying the cluster ID and the number of gambling premises within that cluster. Each polygon is sized according to the number of gambling premises it contains. Gambling premises inside each cluster are shown also in blue, while unclustered (noise) points are shown in black. Each point (a gambling premise GP) has a popup displaying its ID.

Load data

Load the geographical data (spatial points dataframe) containing the coordinates of gambling premises.

xy <- readRDS("data/xy.rds")

MinPts=4 with eps=500m

Load dataframe with coordinates and cluster assignments

#> # A tibble: 6 × 5
#>    LONG   LAT cluster    ID   Pop
#>   <dbl> <dbl> <fct>   <int> <dbl>
#> 1 -2.10  57.1 0        7246     0
#> 2 -2.10  57.1 131      7929     4
#> 3 -2.10  57.1 131      4660     4
#> 4 -2.11  57.1 130      6787     9
#> 5 -2.11  57.1 130      5866     9
#> 6 -2.11  57.1 130      4658     9
#> [1] 8761    5

Number of clusters (excluding noise):

#> [1] 131

Number of noise points:

#> [1] 260

Leaflet map for MinPts=4, eps=500m

MinPts=5 with eps=500m

Load dataframe with coordinates and cluster assignments

#> # A tibble: 6 × 5
#>    LONG   LAT cluster    ID   Pop
#>   <dbl> <dbl> <fct>   <int> <dbl>
#> 1 -2.10  57.1 512      7246    56
#> 2 -2.10  57.1 512      7929    56
#> 3 -2.10  57.1 512      4660    56
#> 4 -2.11  57.1 512      6787    56
#> 5 -2.11  57.1 512      5866    56
#> 6 -2.11  57.1 512      4658    56
#> [1] 8761    5

Number of clusters (excluding noise):

#> [1] 512

Number of noise points:

#> [1] 1808

Leaflet map for MinPts=5, eps=500m

MinPts=10 with eps=500m

Load dataframe with coordinates and cluster assignments

#> # A tibble: 6 × 5
#>    LONG   LAT cluster    ID   Pop
#>   <dbl> <dbl> <fct>   <int> <dbl>
#> 1 -2.10  57.1 245      7246    56
#> 2 -2.10  57.1 245      7929    56
#> 3 -2.10  57.1 245      4660    56
#> 4 -2.11  57.1 245      6787    56
#> 5 -2.11  57.1 245      5866    56
#> 6 -2.11  57.1 245      4658    56
#> [1] 8761    5

Number of clusters (excluding noise):

#> [1] 245

Number of noise points:

#> [1] 3119

Leaflet map for MinPts=10, eps=500m

MinPts=15 with eps=500m

Load dataframe with coordinates and cluster assignments

#> # A tibble: 6 × 5
#>    LONG   LAT cluster    ID   Pop
#>   <dbl> <dbl> <fct>   <int> <dbl>
#> 1 -2.10  57.1 143      7246    56
#> 2 -2.10  57.1 143      7929    56
#> 3 -2.10  57.1 143      4660    56
#> 4 -2.11  57.1 143      6787    56
#> 5 -2.11  57.1 143      5866    56
#> 6 -2.11  57.1 143      4658    56
#> [1] 8761    5

Number of clusters (excluding noise):

#> [1] 143

Number of noise points:

#> [1] 3236

Leaflet map for MinPts=15, eps=500m

MinPts=20 with eps=500m

Load dataframe with coordinates and cluster assignments

#> # A tibble: 6 × 5
#>    LONG   LAT cluster    ID   Pop
#>   <dbl> <dbl> <fct>   <int> <dbl>
#> 1 -2.10  57.1 83       7246    56
#> 2 -2.10  57.1 83       7929    56
#> 3 -2.10  57.1 83       4660    56
#> 4 -2.11  57.1 83       6787    56
#> 5 -2.11  57.1 83       5866    56
#> 6 -2.11  57.1 83       4658    56
#> [1] 8761    5

Number of clusters (excluding noise):

#> [1] 83

Number of noise points:

#> [1] 2646

Leaflet map for MinPts=20, eps=500m


Summary statistics


MinPts Parameter Number of Clusters Unclustered Points Largest Cluster Size Smallest Cluster Size
4 131 260 7341 4
5 512 1808 774 5
10 245 3119 94 10
15 143 3236 374 15
20 83 2646 1492 21