First release (experimental). flowmap() routes origin-destination flows through shared corridors and draws them as SVG, with an optional schematic (octilinear) layout; flowmap_json() is the JSON door of the package’s Rust core (the crate ‘milkflow’); write_svg(), print(), format(), plot() and a knit_print() method for knitr. Points from ‘sf’ in a projected CRS are accepted.
Lines mode: with a column of categories in flows (category, by default the column "category" when there is one) and lines = "auto", each corridor is split into one line per category, ordered to cross little; at most max_categories categories, the others merged into “other”. The lines are in $spec$lines (a long data frame) and $spec$legend$categories; print() shows the share of each category. The SVG figure, the interactive page and the TikZ picture draw the lines: one colour per category, joined at the nodes, with a legend of the categories. The style fields lines, line_width and line_colours control the drawing; lang sets the language of the fixed texts ("pt", default, or "en").
Filters: flowmap(filter = ) chooses the pairs that design the corridors among the filters of the core: "top_k" (the default, with k), "dominant" (Nystuen and Dacey’s dominant flows), "disparity" (the backbone of Serrano et al.), "largest", "share" and "threshold", by name or as a list with the parameters (list(kind = "disparity", alpha = 0.01)).
flowmap(schematic_options = ) passes the options of the schematic layout (sector_slack, fallback_slack, spacing, bridge_cap, spread and the weights) to the core.
Interactive page: flowmap(html = TRUE) adds $html, one self-contained HTML file (no network) with focus on places, segments and lines, written to a file by write_html().
The warnings of the core (repeated pairs summed, nodes merged, categories merged into “other”, a looser schematic rule) are signalled by flowmap() as one R warning of class milkflow_warning, and still listed by print().
Building from source needs Rust 1.85 or later (was 1.88).
TikZ output: flowmap(tikz = TRUE) adds $tikz and $schematic_tikz, written to a file by write_tikz(). The picture is drawn from the same scene as the SVG figure: lines of the categories, split lanes, rails, junctions, themes, palettes, opacities, corners, title, legend and honesty line in the language of the style; LaTeX typesets the text.
GeoJSON output: flowmap(geojson = TRUE) adds $geojson and $schematic_geojson, written to a file by write_geojson(): the drawn figure as GeoJSON — each paint operation in paint order, in the input’s coordinates (reproject before using it as RFC 7946 lon/lat); places[].uses tells which segments/categories each place’s flows use.
Groups at several levels: group names a column of nodes, passed to the core as a level of the nodes’ groups, so that one table can hold nested levels (group = "district", then group = "region"); $spec$meta$params$group records the level. group = TRUE still takes the column "group". A level column without any value is an error.
Automatic aggregation: flowmap(aggregate = 30) merges the places by proximity (near neighbours only) until 30 remain, each group drawn at and named after its heaviest place; places without a near neighbour stay alone and do not count; method = "ward" (default, compact groups) or "gravity" (the lightest group joins its heaviest near neighbour); aggregate = list(to = 30, keep = ids) protects nodes. $spec$meta$aggregation$members lists the ids merged into each place. Not combined with group.
Junctions: with skeleton_source = "input", the nodes of the user’s skeleton where no flow starts or ends have kind = "junction" in $spec$nodes (the others "place"), are drawn as dots, and are counted in $spec$meta$metrics$junctions and by print().
A sparse filter (any but "top_k") with represent = "all" warns when the largest detour is above 4, suggesting represent = "design".
The schematic layout lays out runs of nodes with two segments as one path ($schematic_spec$meta$params$schematic$chains counts them).
style$frame_on_boundary: the places outside the frame are not drawn and are counted in the honesty line, and the segments towards them end at the edge of the map with an arrowhead.
style documents every drawing option of the core (themes, palettes, split lanes and their colours, rails, corners, place shapes, opacities); it is passed through as JSON, so options added to the core work without a change on the R side. An unknown or invalid field names the field.
Errors of the core that refer to a flow or a node by its position (“flow #0”) name the row of flows or nodes instead, counted from 1; an invalid filter, schematic_options or style names the argument and the field.
demo_flows has a category column (trip purpose).
The drawing specification ($spec, version 0.1) is not yet declared stable: its fields may change in later releases.
Vignettes: “Flow maps with milkflow” (the tour), “How a flow map is made” (the steps of the pipeline and the argument that steers each) and “How the package is built” (the Rust core, the JSON door and the milkflow object), with diagrams. The package has a site: https://strategicprojects.github.io/milkflow/r/.