flowmap_sf: Export flow edges and nodes as simple features.

View source: R/flowmap_sf.R

flowmap_sfR Documentation

Export flow edges and nodes as simple features.

Description

Export flow edges and nodes as simple features.

Usage

flowmap_sf(
  flowdat = NULL,
  od = NULL,
  nodes = NULL,
  k_nodes = NULL,
  node_buffer_factor = 1.2,
  node_fill_factor = NULL,
  node_radius_factor = 1,
  edge_offset_factor = 1,
  edge_width_factor = 1.2,
  arrow_point_angle = 45,
  crs = 4326
)

Arguments

flowdat

Input dataframe. See details below.

od

As an alternative to flowdat, dataframe with the origin-destination pairs and the flow between them. Must contain the columns o, d, value. nodes must be provided as well. See details below.

nodes

As an alternative to flowdat, a dataframe with the nodes of the network. Must contain the columns name, x, y. See details below.

k_nodes

Number of clusters to group nodes into. If defined, nodes will be clustered hierarchically based on spatial proximity. By default, no clustering will be applied.

node_buffer_factor

Controls the distance between the nodes and the edges ( in multiple of the nodes' radii).

node_fill_factor

Controls the downscaling of the fill of the nodes ( as to not outshine the edges ).

node_radius_factor

Controls the size of the nodes.

edge_offset_factor

Controls the distance between the parallel arrows.

edge_width_factor

Controls the width of the edges.

arrow_point_angle

Controls the pointiness of the edges.

crs

The EPSG code for the coordinate reference system of the input data. Default is 4326 (WGS84).

Value

A list with two elements: edges and nodes. Each element is a sf object.

For the edges, contains the following columns:

  • orig: The unique id of the origin node.

  • dest: The unique id of the destination node.

  • flow: The flow from a to b.

And for the nodes:

  • name: The unique id of the node.

  • flowsum: The sum of all flows involving that node.

Examples

testdata <-
data.frame(
 id_a = c("X1","X2","X3","X3","X1"),
 id_b = c("X8","X7","X1","X8","X7"),
 xa = c(2,14,10,10,2),
 ya = c(6,10,9,9,6),
 xb = c(10,4,2,10,4),
 yb = c(4,10,6,4,10),
 flow_ab = c(2,1,1,1,1),
 flow_ba = c(5,1,1,1,2))
sf_objects <- flowmap_sf(flowdat = testdata,crs=4326)
sf_edges <- sf_objects$edges
sf_nodes <- sf_objects$nodes

flowmapper documentation built on June 11, 2025, 5:08 p.m.