Hi friends,
I've created a dot-density map of a particular location, which involves around 60,000 points (each point = 100 people). I was wondering if there was a way to improve the speed with which the map renders when you zoom in and out.
The map is produced using Leaflet, which I want to publish on my blogdown site. However, with 60,000 points, the map is understandably quite slow.
Here's a simplified example of what my code and map look like:
library(tidyverse)
library(leaflet)
library(sf)
# Randomly generate 60,000 coordinate pairs
set.seed(1)
num <- 60000
df <- data.frame(
lon = runif(num, min = -97.06, max = -96.5),
lat = runif(num, min = 32.540, max = 32.957))
# Convert to a simple feature
df <- st_as_sf(df, coords = c("lon", "lat"), crs = 4326, agr = "constant")
# Create map
leaflet() %>%
addProviderTiles(providers$Esri.WorldGrayCanvas) %>%
addCircles(data = df, weight = 0)
I was wondering if there was a way to improve this, without reducing the number of dots or using clusters?
For example, could I make it so that the points appear as an image or a tile on the map instead? (I am probably using the wrong terminology here, but hopefully you get my meaning).
Grateful for any tips you can provide. Thanks for your time.