It's currently not possible to have a multi-coloured path
, but it is on my todo list.
To achieve what you're after you'll have to use a line
layer, which takes an 'origin' and 'destination' and draws a straight line (i.e., the constituent parts of a path
)
To get the Origin-Destination columns we need to decompose the sf
object into a data.frame, add the '_to' columns, then make it an sf
object again.
(I also have a todo to allow data.frames to use Z and M, but for now we have to do this final conversion to sf
again)
library(data.table)
library(sfheaders)
df <- sfheaders::sf_to_df( one_day, fill = TRUE )
setDT( df )[
, `:=`(
x_to = shift(x, type = "lead")
, y_to = shift(y, type = "lead")
, z_to = shift(z, type = "lead")
, m_to = shift(m, type = "lead")
)
, by = flight
]
df <- df[ !is.na( x_to ) ]
df$origin <- sfheaders::sfc_point(
obj = df
, x = "x"
, y = "y"
, z = "z"
, m = "m"
)
df$destination <- sfheaders::sfc_point(
obj = df
, x = "x_to"
, y = "y_to"
, z = "z_to"
, m = "m_to"
)
sf <- sf::st_as_sf( df )
mapdeck(
style = mapdeck_style("dark")
) %>%
add_line(
data = sf
, origin = "origin"
, destination = "destination"
, stroke_colour = "z"
)
