add_grid: Add Grid

Description Usage Arguments Details data Examples

View source: R/map_layer_grid.R

Description

The Grid Layer renders a grid heatmap based on an array of points. It takes the constant size all each cell, projects points into cells. The color and height of the cell is scaled by number of points it contains.

Usage

1
2
3
4
5
add_grid(map, data = get_map_data(map), lon = NULL, lat = NULL,
  polyline = NULL, colour_range = NULL, cell_size = 1000,
  extruded = TRUE, elevation_scale = 1, auto_highlight = FALSE,
  highlight_colour = "#AAFFFFFF", layer_id = NULL,
  update_view = TRUE, focus_layer = FALSE)

Arguments

map

a mapdeck map object

data

data to be used in the layer. All coordinates are expected to be in Web Mercator Projection

lon

column containing longitude values

lat

column containing latitude values

polyline

optional column of data containing the polylines, if using encoded polylines

colour_range

vector of 6 hex colours

cell_size

size of each cell in meters

extruded

logical indicating if cells are elevated or not

elevation_scale

cell elevation multiplier

auto_highlight

logical indicating if the shape under the mouse should auto-highlight

highlight_colour

hex string colour to use for highlighting. Must contain the alpha component.

layer_id

single value specifying an id for the layer. Use this value to distinguish between shape layers of the same type. Layers with the same id are likely to conflict and not plot correctly

update_view

logical indicating if the map should update the bounds to include this layer

focus_layer

logical indicating if the map should update the bounds to only include this layer

Details

add_grid supports POINT and MULTIPOINT sf objects

data

If the data is a simple feature object, the geometry column is automatically detected. If the sf object contains more than one geometry column and you want to use a specific one, you'll need to set the active geometry using sf::st_geometry( x ) <- "your_column" , where "your_column" is the name of the column you're activating. See ?sf::st_geometry

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
## You need a valid access token from Mapbox
key <- 'abc'

df <- read.csv(paste0(
'https://raw.githubusercontent.com/uber-common/deck.gl-data/master/',
'examples/3d-heatmap/heatmap-data.csv'
))

df <- df[ !is.na(df$lng ), ]

mapdeck( token = key, style = mapdeck_style("dark"), pitch = 45 ) %>%
add_grid(
  data = df
  , lat = "lat"
  , lon = "lng"
  , cell_size = 5000
  , elevation_scale = 50
  , layer_id = "grid_layer"
  , auto_highlight = TRUE
)

## using sf object
library(sf)
sf <- sf::st_as_sf( df, coords = c("lng", "lat"))

mapdeck( token = key, style = mapdeck_style("dark"), pitch = 45 ) %>%
add_grid(
  data = sf
  , cell_size = 5000
  , elevation_scale = 50
  , layer_id = "grid_layer"
  , auto_highlight = TRUE
)

mapdeck documentation built on Jan. 22, 2019, 5:04 p.m.