Created
January 3, 2017 17:21
-
-
Save RCura/a45ccfaa221afabc16fb47a80eaca35e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
--- | |
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(mediumSample) %>% | |
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