# \donttest{
## You need a valid access token from Mapbox
set_token("MAPBOX_TOKEN")
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_greatcircle(
data = flights
, layer_id = "greatcircle_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_greatcircle(
data = flights
, layer_id = "greatcircle_layer"
, origin = c("start_lon", "start_lat")
, destination = c("end_lon", "end_lat")
, 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", keep = TRUE )
destination <- sfheaders::sfc_point( flights, x = "end_lon", y = "end_lat" )
sf_flights$destination <- destination
mapdeck() %>%
add_greatcircle(
data = sf_flights
, origin = 'geometry'
, destination = 'destination'
, layer_id = 'greatcircles'
, stroke_from = "airport1"
, stroke_to = "airport2"
)
# }
Run the code above in your browser using DataLab