# \donttest{
## 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("",flights$airport1, " - ", flights$airport2, "")
mapdeck( style = mapdeck_style("dark"), pitch = 45 ) %>%
add_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"
, tooltip = "info"
, auto_highlight = TRUE
, legend = TRUE
, legend_options = list(
stroke_from = list( title = "Origin airport" ),
css = "max-height: 100px;")
)
mapdeck( style = mapdeck_style("dark")) %>%
add_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"
)
## Arcs can have an elevated start & destination
flights$start_elev <- sample(100000:1000000, size = nrow(flights), replace = TRUE )
mapdeck( style = mapdeck_style("dark")) %>%
add_arc(
data = flights
, layer_id = "arc_layer"
, origin = c("start_lon", "start_lat", "start_elev")
, destination = c("end_lon", "end_lat", "start_elev")
, stroke_from = "airport1"
, stroke_to = "airport2"
, stroke_width = "stroke"
)
## Using a 2-sfc-column sf object
library(sfheaders)
sf_flights <- sfheaders::sf_point(
flights
, x = "start_lon"
, y = "start_lat"
, z = "start_elev"
, keep = TRUE
)
destination <- sfheaders::sfc_point(
flights
, x = "end_lon"
, y = "end_lat"
, z = "start_elev"
)
sf_flights$destination <- destination
mapdeck(
) %>%
add_arc(
data = sf_flights
, origin = 'geometry'
, destination = 'destination'
, layer_id = 'arcs'
, stroke_from = "airport1"
, stroke_to = "airport2"
)
## using a brush
mapdeck(
, style = mapdeck_style("light")
) %>%
add_arc(
data = sf_flights
, origin = 'geometry'
, destination = 'destination'
, layer_id = 'arcs'
, stroke_from = "airport1"
, stroke_to = "airport2"
, stroke_width = 4
, brush_radius = 500000
)
# }
Run the code above in your browser using DataLab