
Adds a FlowmapGL layer for visualizing origin-destination flows between point locations.
Source:R/flowmap.R
add_flowmap.RdAdds a FlowmapGL layer for visualizing origin-destination flows between point locations.
Usage
add_flowmap(
map,
id,
locations,
flows,
flow_color_scheme = "Teal",
flow_opacity = 1,
flow_dark_mode = "auto",
flow_blend = "auto",
flow_fade_amount = 50,
flow_highlight_color = "#ff9b29",
flow_locations_enabled = TRUE,
flow_location_totals_enabled = TRUE,
flow_location_labels_enabled = FALSE,
flow_lines_rendering_mode = c("straight", "animated-straight", "curved"),
flow_line_thickness_scale = 1,
flow_line_curviness = 1,
flow_clustering_enabled = TRUE,
flow_clustering_auto = TRUE,
flow_clustering_level = NULL,
flow_fade_enabled = TRUE,
flow_fade_opacity_enabled = FALSE,
flow_adaptive_scales_enabled = TRUE,
flow_temporal_scale_domain = c("selected", "all"),
flow_max_top_flows_display_num = 5000,
flow_endpoints_in_viewport_mode = c("any", "both"),
flow_time_column = NULL,
flow_selected_time_range = NULL,
flow_selected_locations = NULL,
flow_location_filter_mode = c("ALL", "INCOMING", "OUTGOING", "BETWEEN"),
tooltip = TRUE,
popup = FALSE,
tooltip_style = NULL,
popup_style = NULL,
visibility = c("visible", "none"),
before_id = NULL,
slot = NULL
)Arguments
- map
A map object created by
mapboxgl()ormaplibre().- id
A unique layer ID.
- locations
A data frame or
sfpoint object with location data. Data frames must includeid,lat, andloncolumns.sfpoint objects must includeid; coordinates are transformed to EPSG:4326 and serialized aslon/lat.- flows
A data frame with
origin,dest, andcountcolumns.- flow_color_scheme
FlowMapGL preset color scheme name, a character vector of at least two CSS colors, or a
mapgl_continuous_scaleobject created byinterpolate_palette(). Preset names are case-sensitive; useflowmap_color_schemes()to list them.- flow_opacity
Layer opacity between 0 and 1.
- flow_dark_mode
Logical (
TRUEorFALSE), or"auto"; whether to use FlowMapGL dark-mode colors. If"auto", the mode is dynamically detected based on the map style.- flow_blend
Logical (
TRUEorFALSE),"auto", or a character string specifying a CSS mix-blend-mode.Valid modes are:
"normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color", and"luminosity".Recommendations:
On dark basemaps:
"screen"looks best, creating a glowing additive effect where flows overlap.On light basemaps:
"multiply"or"darken"looks best, increasing contrast against the light background.
If
"auto", automatically chooses"screen"for dark styles and"multiply"for light styles. Ifbefore_idorslotis specified (interleaved mode),"auto"quietly disables blending (FALSE) without throwing a warning. IfTRUE, defaults to"screen"whenflow_dark_modeisTRUE, and"multiply"whenFALSE. IfFALSE, no blending is applied. Note: CSS blending requires a standalone canvas overlay and is ignored whenbefore_idorslotis specified.- flow_fade_amount
Controls how much lower-magnitude flows fade compared to higher ones. Range: 0-100.
- flow_highlight_color
Color used for highlighting hovered elements.
- flow_locations_enabled
Whether to show location circles.
- flow_location_totals_enabled
Whether to show incoming/outgoing totals as concentric circles at each location.
- flow_location_labels_enabled
Whether to show text labels at locations.
- flow_lines_rendering_mode
Controls how flow lines are rendered:
"straight","animated-straight", or"curved".- flow_line_thickness_scale
Multiplier for flow line thickness.
- flow_line_curviness
Multiplier for flow line curviness (only used when
flow_lines_rendering_modeis"curved").- flow_clustering_enabled
Whether to cluster nearby locations when zoomed out.
- flow_clustering_auto
Whether to automatically adjust clustering level based on zoom.
- flow_clustering_level
Fixed clustering zoom level. Only used when
flow_clustering_autoisFALSE.- flow_fade_enabled
Whether to apply color fading to lower-magnitude flows.
- flow_fade_opacity_enabled
Whether to also fade opacity for lower-magnitude flows.
- flow_adaptive_scales_enabled
Whether to adapt flow thickness and color scales to the current viewport. This controls the spatial scale domain while panning and zooming.
- flow_temporal_scale_domain
For temporal flowmaps, whether flow thickness and color scales use only the currently selected time range (
"selected") or all flow data across the full time extent ("all").- flow_max_top_flows_display_num
Maximum number of flows to display.
- flow_endpoints_in_viewport_mode
Controls when a flow is considered visible based on endpoint locations:
"any"or"both".- flow_time_column
Optional column name in
flowsfor time data.- flow_selected_time_range
Optional vector of two dates (or strings) for initial time filtering.
- flow_selected_locations
Optional vector of location IDs to select.
- flow_location_filter_mode
Optional location filter mode:
"ALL","INCOMING","OUTGOING", or"BETWEEN".- tooltip
Hover tooltip content. Use
FALSE/NULLto disable,TRUEfor the default, a column name, a{brace}template, aconcat()/number_format()expression, or a namedlist(location = , flow = )to set different content for hovered locations vs flows. Available fields are, for locations:name,id,lat,lon,incoming,outgoing,internal(plus anylocationscolumns); for flows:count,origin_id,origin_name,dest_id,dest_name(plus anyflowscolumns).- popup
Click popup content. Same forms as
tooltip; defaults toFALSE(disabled).- tooltip_style
Tooltip appearance. A preset string (
"light","dark", or"auto") or atooltip_style()object (colors, border, radius, font, padding, shadow, andposition = "floating"/"anchored"). Defaults to a light/dark preset matchingflow_dark_mode.- popup_style
Popup appearance; same forms as
tooltip_style.- visibility
Whether the layer is initially
"visible"or"none".- before_id
Optional map layer ID to render before.
- slot
Optional Mapbox Standard slot.
Details
Mapbox and MapLibre layer paint arguments such as fill_color,
circle_color, and line_color require a scalar CSS color or a style
expression. Use interpolate_palette(...)$expression for data-driven layer
color ramps. FlowMapGL's flow_color_scheme accepts a preset name such as
"Teal", a plain color ramp such as c("red", "white", "blue"), or an
interpolate_palette(...) scale object.
Flow scale domains have separate spatial and temporal controls.
flow_adaptive_scales_enabled = TRUE rescales flow thickness and color for
the current viewport; FALSE keeps the scale tied to the broader map extent.
For temporal flowmaps, flow_temporal_scale_domain = "selected" rescales
within the selected time-control interval, while "all" keeps the scale
comparable across the full time extent.
Examples
# Create a flowmap centered on Montréal using the bundled datasets
maplibre(
style = carto_style("dark-matter"),
center = c(-73.58, 45.50),
zoom = 11,
projection = "mercator"
) |>
add_flowmap(
id = "bixi-rides",
locations = bixi_locations,
flows = bixi_flows,
flow_time_column = "time",
flow_color_scheme = "Teal",
flow_dark_mode = TRUE
)
# To animate the flows over time, pair the flowmap with a window-mode
# slider that targets the same layer id; see [add_slider_control()].