add_pointcloud: Add Pointcloud

Description Usage Arguments Details transitions data legend id Examples

View source: R/map_layer_pointcloud.R

Description

The Pointcloud Layer takes in coordinate points and renders them as circles with a certain radius.

Usage

1
2
3
4
5
6
7
8
add_pointcloud(map, data = get_map_data(map), lon = NULL, lat = NULL,
  elevation = NULL, polyline = NULL, radius = 10,
  fill_colour = NULL, fill_opacity = NULL, tooltip = NULL,
  auto_highlight = FALSE, highlight_colour = "#AAFFFFFF",
  light_settings = list(), layer_id = NULL, id = NULL,
  palette = "viridis", na_colour = "#808080FF", legend = FALSE,
  legend_options = NULL, legend_format = NULL, update_view = TRUE,
  focus_layer = FALSE, transitions = NULL)

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

elevation

column containing the elevation values

polyline

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

radius

value in pixels of each point

fill_colour

column of data or hex colour for the fill colour. transition enabled

fill_opacity

value between 0 and 255. Either a string specifying the column of data containing the fill opacity of each shape, or a single value to be applied to all the shapes

tooltip

variable of data containing text or HTML to render as a tooltip

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.

light_settings

list of light setting parameters. See light_settings

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

id

an id value in data to identify layers when interacting in Shiny apps.

palette

string or matrix. String will be one of colourvalues::colour_palettes(). A matrix is a 3 or 4 column numeric matrix of values between [0, 255], where the 4th column represents the alpha.

na_colour

hex string colour to use for NA values

legend

either a logical indiciating if the legend(s) should be displayed, or a named list indicating which colour attributes should be included in the legend.

legend_options

A list of options for controlling the legend.

legend_format

A list containing functions to apply to legend values. See section legend

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

transitions

list specifying the duration of transitions.

Details

add_pointcloud supports POINT and MULTIPOINT sf objects

transitions

The transitions argument lets you specify the time it will take for the shapes to transition from one state to the next. Only works in an interactive environment (Shiny) and on WebGL-2 supported browsers and hardware.

The time is in milliseconds

Available transitions for pointcloud

list( position = 0, fill_colour = 0 )

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

legend

The legend_options can be used to control the appearance of the legend. This should be a named list, where the names are one of

If the layer allows different fill and stroke colours, you can use different options for each. See examples in add_arc.

The legend_format can be used to control the format of the values in the legend. This should be a named list, where the names are one of

depending on which type of colouring the layer supports.

The list elements must be functions to apply to the values in the legend.

id

The id is returned to your R session from an interactive shiny environment by observing layer clicks. This is useful for returning the data.frame row relating to the cliked shape.

From within a shiny server you would typically use observeEvent({input$map_arc_click}), where 'map' is the map_id supplied to mapdeckOutput(), and 'arc' is the layer you are clicking on

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
## You need a valid access token from Mapbox
key <- 'abc'

df <- capitals
df$z <- sample(10000:10000000, size = nrow(df))

mapdeck(token = key, style = mapdeck_style("dark")) %>%
add_pointcloud(
  data = df
  , lon = 'lon'
  , lat = 'lat'
  , elevation = 'z'
  , layer_id = 'point'
  , fill_colour = "country"
  , tooltip = "country"
  , update_view = FALSE
)

## as an sf object wtih a Z attribute
library(sf)
sf <- sf::st_as_sf( df , coords = c("lon","lat","z"))

mapdeck(token = key, style = mapdeck_style("dark")) %>%
add_pointcloud(
  data = sf
  , layer_id = 'point'
  , fill_colour = "country"
  , tooltip = "country"
  , update_view = FALSE
)

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