Skip to content

Instantly share code, notes, and snippets.

@RCura
Created January 3, 2017 17:23
Show Gist options
  • Save RCura/8f728d205de3c03b7c142233a826e3ab to your computer and use it in GitHub Desktop.
Save RCura/8f728d205de3c03b7c142233a826e3ab to your computer and use it in GitHub Desktop.
---
title: "WebGLHeatmap-small"
output:
html_notebook: default
---
## 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')
devtools::install_github('bhaskarvk/leaflet.extras')
```
## Display Heatmap
```{r show heatmap}
library(leaflet)
library(leaflet.extras)
leaflet(mediumSample) %>%
addProviderTiles("CartoDB.DarkMatter") %>%
addWebGLHeatmap(lng=~Long,
lat=~Lat,
size = 5,
units = "px")
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment