Created
March 16, 2017 15:11
-
-
Save mdsumner/93cefff4172d50006e670148b6b2e1e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#devtools::install_github('rstudio/leaflet') | |
library(leaflet) | |
library(raster) | |
## fake a raster | |
r <- raster(volcano) | |
## this volcano is in NZ, but we are ignoring that with huge abandon | |
extent(r) <- extent(100, 150, -42, -15) | |
projection(r) <- "+init=epsg:4326" | |
n <- 768 | |
set.seed(1) | |
pts <- cbind(runif(n, xmin(r), xmax(r)), runif(n, ymin(r), ymax(r))) | |
## create a trad MASS xyz list "raster" | |
## and convert to raster | |
kde <- raster(MASS::kde2d(pts[, 1], pts[, 2])) | |
## contour the raster (picks defaults, same as ?contour) | |
cont <- rasterToContour(kde) | |
## give to leaflet | |
leaflet() %>% addTiles() %>% addPolylines(data = cont) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment