Skip to content

Instantly share code, notes, and snippets.

@RCura
Created January 3, 2017 17:19
Show Gist options
  • Save RCura/200bd2c1c57a4ce6cd078df504f0f65b to your computer and use it in GitHub Desktop.
Save RCura/200bd2c1c57a4ce6cd078df504f0f65b to your computer and use it in GitHub Desktop.
---
title: "Leaflet.heat"
output: html_notebook
---
## Data preparation
```{r data loading}
library(tibble)
library(dplyr)
paris <- list()
paris$min <- list(Long = 2.199669, Lat = 48.806185)
paris$max <- list(Long = 2.481194, Lat = 48.899258)
paris$mean <- list(Long = mean(c(paris$min$Long, paris$max$Long)),
Lat = mean(c(paris$min$Lat, paris$max$Lat)))
paris$sd <- list(Long = (paris$max$Long - paris$min$Long) / 2,
Lat = (paris$max$Lat - paris$min$Lat) / 2)
```
```{r sample creation}
set.seed(1000)
bigSample <- data_frame(Long = rnorm(n = 500E3, mean = paris$mean$Long, sd = paris$sd$Long),
Lat = rnorm(n = 500E3, mean = paris$mean$Lat, sd = paris$sd$Lat))
mediumSample <- bigSample %>%
sample_n(size = 100E3)
smallSample <- bigSample %>%
sample_n(size = 10E3)
```
## Package preparation
```{r remove packages, warning = FALSE, eval=FALSE}
remove.packages("leaflet")
remove.packages("leaflet.extras")
```
```{r install packages, eval=FALSE}
devtools::install_github('rstudio/leaflet', ref = "feature/heatmap")
```
## Display Heatmap
```{r show heatmap}
library(leaflet)
leaflet(smallSample) %>%
addProviderTiles("CartoDB.DarkMatter") %>%
addHeatmap(lng = ~ Long,
lat = ~ Lat,
radius = 10,
minOpacity = 1,
intensity = 1
)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment