add_animated_arc: Add animated arc

Description Usage Arguments Details data legend id Examples

View source: R/map_layer_animated_arc.R

Description

The Arc Layer renders raised arcs joining pairs of source and target coordinates

Usage

 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
add_animated_arc(
  map,
  data = get_map_data(map),
  layer_id = NULL,
  origin,
  destination,
  id = NULL,
  stroke_from = NULL,
  stroke_from_opacity = NULL,
  stroke_to = NULL,
  stroke_to_opacity = NULL,
  stroke_width = NULL,
  frequency = 1,
  animation_speed = 3,
  trail_length = 5,
  tilt = NULL,
  height = NULL,
  tooltip = NULL,
  auto_highlight = FALSE,
  highlight_colour = "#AAFFFFFF",
  legend = F,
  legend_options = NULL,
  legend_format = NULL,
  palette = "viridis",
  na_colour = "#808080FF",
  update_view = TRUE,
  focus_layer = FALSE,
  transitions = NULL,
  digits = 6,
  brush_radius = NULL
)

Arguments

map

a mapdeck map object

data

data to be used in the layer. All coordinates are expected to be EPSG:4326 (WGS 84) coordinate system

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

origin

vector of longitude and latitude columns, and optionally an elevation column, or an sfc column

destination

vector of longitude and latitude columns, and optionally an elevatino column, or an sfc column

id

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

stroke_from

column of data or hex colour to use as the staring stroke colour. IIf using a hex colour, use either a single value, or a column of hex colours on data

stroke_from_opacity

Either a string specifying the column of data containing the stroke opacity of each shape, or a value between 1 and 255 to be applied to all the shapes. If a hex-string is used as the colour, this argument is ignored and you should include the alpha on the hex string

stroke_to

column of data or hex colour to use as the ending stroke colour. If using a hex colour, use either a single value, or a column of hex colours on data

stroke_to_opacity

Either a string specifying the column of data containing the stroke opacity of each shape, or a value between 1 and 255 to be applied to all the shapes. If a hex-string is used as the colour, this argument is ignored and you should include the alpha on the hex string

stroke_width

width of the stroke in pixels

frequency

column of data, or a single value indicating the number of arcs generated in each animation

animation_speed

the speed of animation

trail_length

the length of trail of each arc

tilt

value to tilt the arcs to the side, in degrees [-90, 90]

height

value to multiply the height.

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.

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

palette

string or matrix. String will be one of colourvalues::colour_palettes(). A matrix must have at least 5 rows, and 3 or 4 columns of values between [0, 255], where the 4th column represents the alpha. You can use a named list to specify a different palette for different colour options (where available), e.g. list(fill_colour = "viridis", stroke_colour = "inferno")

na_colour

hex string colour to use for NA values

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.

digits

number of digits for rounding coordinates

brush_radius

radius of the brush in metres. Default NULL. If supplied, the arcs will only show if the origin or destination are within the radius of the mouse. If NULL, all arcs are displayed

Details

add_arc supports POINT sf objects

MULTIPOINT objects will be treated as single points. That is, if an sf objet has one row with a MULTIPOINT object consisting of two points, this will be expanded to two rows of single POINTs. Therefore, if the origin is a MULTIPOINT of two points, and the destination is a single POINT, the code will error as there will be an uneven number of rows

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
31
32
33
34
35
36
37
38
39
40
41
## You need a valid access token from Mapbox
key <- 'abc'
set_token( key )

url <- 'https://raw.githubusercontent.com/plotly/datasets/master/2011_february_aa_flight_paths.csv'
flights <- read.csv(url)
flights$id <- seq_len(nrow(flights))
flights$stroke <- sample(1:3, size = nrow(flights), replace = TRUE)
flights$info <- paste0("<b>",flights$airport1, " - ", flights$airport2, "</b>")

mapdeck( style = mapdeck_style("dark"), pitch = 45 ) %>%
  add_animated_arc(
  data = flights
  , layer_id = "arc_layer"
  , origin = c("start_lon", "start_lat")
  , destination = c("end_lon", "end_lat")
  , stroke_from = "airport1"
  , stroke_to = "airport2"
  , stroke_width = "stroke"
  , trail_length = 10
  , tooltip = "info"
  , auto_highlight = TRUE
  , legend = TRUE
  , legend_options = list(
    stroke_from = list( title = "Origin airport" ),
    css = "max-height: 100px;")
 )

## faster animation_speed
mapdeck( style = mapdeck_style("dark")) %>%
  add_animated_arc(
  data = flights
  , layer_id = "arc_layer"
  , origin = c("start_lon", "start_lat")
  , destination = c("end_lon", "end_lat")
  , stroke_from = "airport1"
  , stroke_to = "airport2"
  , stroke_width = "stroke"
  , trail_length = 10
  , animation_speed = 15
  )

mapdeck documentation built on Sept. 4, 2020, 9:07 a.m.