Here’s one way to do kernel density estimation in R spatial
Packages This requires a surprising number of moving parts (at least the way I did it):
library(sf) library(tmap) library(spatstat) library(maptools) library(raster) library(dplyr) Data The data are some point data (Airbnb listings from here) and some polygon data (NZ census Statistical Area 2 data).