bake_donuts: Bake donuts

Description Usage Arguments Examples

View source: R/bake_donuts.R

Description

Bake donuts

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
bake_donuts(
  x,
  var,
  totals = NULL,
  text = list(legend_title = "Region", legend_other = "Other region", legend_stay =
    "Home region", popup_residents = "Residents", popup_stay = "Staying", popup_other =
    "    to other regions", popup_inflow = "From other regions",
    popup_outflow = "Leaving", popup_to = "    ", edge_to = "to",
    edge_flow = "Flow"),
  groupname = "Data",
  highlight = NULL,
  pal = c("blue", "grey70"),
  donut_size_min = NA,
  donut_size_max = NA,
  donut_scale = 1.5,
  flow_th = NA,
  flow_max = NA,
  flow_buffer = NA,
  flow_scale = 10,
  round_to = 1,
  edge_incoming = TRUE,
  popup_perc_totals = TRUE,
  popup_perc_items = FALSE,
  groups = list(),
  mute = NULL,
  legend = TRUE,
  group_label_show = FALSE,
  group_label_cex = 1,
  group_trunc_m = 2000,
  border = NULL,
  tm = NULL,
  title = NULL,
  basemaps = c("Esri.WorldGrayCanvas", "OpenStreetMap")
)

Arguments

x

od object

var

name of the variable in x$E that contain the flow values

totals

total numbers of units per origin. If NULL (default) the totals are derived from x. This parameter is useful, because in some applications, the total may deviate because of rounding errors.

text

list of text labels in the visualization. See default function call for required list items.

groupname

Name of the group what will appear as layer in the interactive map.

highlight

Name(s) of the regions (origins or destinations) that will have a distinct color

pal

color palette. It should have the length of length(highlight) + 2. The first color indicate the flows to elsewhere (except to hightlights), the second color indicates "stay", i.e. flows from A to A. The other colors are used for the regions in highlight.

donut_size_min, donut_size_max, donut_scale

The values that determine the donut size (totals of var per origin) are truncated at donut_size_min and donut_size_max. Next, the value range c(0, donut_size_max) is mapped to the size range c(0, donot_scale).

flow_th,

Only flows of at least flow_th are shown.

flow_max, flow_buffer, flow_scale

The values that determine the flows (specified with var) are truncated at flow_max. Next, flow_buffer is added to those values (to compensate for very thin lines). Next, the value range c(0, flow_max) is mapped to the size range c(0, flow_scale). It is recommende to keep flow_buffer low, e.g. similar to flow_th.

round_to

Rounding of the numbers of x$E[[var]] (useful in case these values are privacy sensitive). Use 1 to round to integers, 100 to round to hundreds, etc.

edge_incoming

Should the edges to drawn from midpoint to destination (so incoming), by default TRUE, or from origin to midpoint (so outgoing)?

popup_perc_totals

Should percentages be shown for totals in the popups?

popup_perc_items

Should percentages be shown for the highlighted regions in the popups?

groups

List of groups that specify grouping of nodes. Each item is a list that contains information for one group. The items should be: codes, a vector of codes of nodes to be grouped; longlat, the long/lat coordinates of the grouped node; name, the name of the grouped node; code, an arbitrary but unique code for the grouped node; donut logical indicating whether the donut for the grouped node should be shown; inflow, logical indicating whether the inflows for the grouped node should be shown; outflow, logical indicating whether the outflows for the grouped node should be shown.

mute

List that specifies which codes are not shown. The items should be codes, a vector of codes of nodes to be muted; donut logical indicating whether the donut for the muted nodes should be shown; inflow, logical indicating whether the inflows for the muted nodes should be shown; outflow, logical indicating whether the outflows for the muted nodes should be shown.

legend

Should the legend be shown?

group_label_show

Should the group labels be printed in the map?

group_label_cex

Text size of the group labels (in case group_label_show)

group_trunc_m

not used

border

sf object with polygons which show the region borders

tm

tmap element that can be used to stack donut maps

title

Title

basemaps

Basemaps See tm_basemap.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
library(odf)
library(donutmaps)
library(tmap)

data("NL_commuting")
data("NL_muni_point")

# Create odf object
x = od(NL_commuting, NL_muni_point, col_orig = "muni_from", col_dest = "muni_to", col_id = "id")

# Define color palette
CBS_pal = c("#d9328a", "#7d4791", "#da5914", "#53a31d", "#0581a2", "#B3B3B3")


# Bake tasty donuts (all commuting traffic)
# Edges are incoming by default
tm = bake_donuts(x,
    var = "value",
    groupname = "Netherlands",
    highlight = c("Amsterdam", "Rotterdam", "Den Haag", "Utrecht"),
    pal = CBS_pal,
    donut_size_min = 30000, donut_size_max = 400000,
    flow_th = 500, flow_max = 20000, flow_buffer = 500, flow_scale = 10,
    donut_scale = 1.75)

# The result is a tmap object, which can best be shown in "view mode"
tmap_mode("view")
tm

# Focus on outgoing edges
tm_out = bake_donuts(x,
    var = "value",
    groupname = "Netherlands",
    highlight = c("Amsterdam", "Rotterdam", "Den Haag", "Utrecht"),
    pal = CBS_pal,
    donut_size_min = 30000, donut_size_max = 400000,
    edge_incoming = FALSE,
    flow_th = 500, flow_max = 20000, flow_buffer = 500, flow_scale = 10,
    donut_scale = 1.75)
tm_out

# Only commute by train
x_train = x
x_train$E = x_train$E[x_train$E$mode == "train", ]

tm_train = bake_donuts(x_train,
    var = "value",
    groupname = "Netherlands",
    highlight = c("Amsterdam", "Rotterdam", "Den Haag", "Utrecht"),
    pal = CBS_pal,
    donut_size_min = 1000, donut_size_max = 20000,
    flow_th = 100, flow_max = 2000, flow_buffer = 100, flow_scale = 15,
    donut_scale = 1.75)
tm_train

mtennekes/donutmaps documentation built on Dec. 21, 2021, 11 p.m.