Skip to contents

movedata2igraph() converts movenet-format movement and (optional) holding data tibbles into an igraph static network representation. This assumes the network is directed with no hyperedges. Loops are allowed; multiplex edges can be made by using edge attributes.

Usage

movedata2igraph(
  movement_data,
  holding_data = NULL,
  incl_nonactive_holdings = FALSE
)

Arguments

movement_data

A movenet-format movement data tibble.

holding_data

A movenet-format holding data tibble (optional).

incl_nonactive_holdings

A logical that indicates whether to include holdings from holding_data that are not present in movement_data. Default is FALSE. If set to TRUE, holdings that don't trade within the period covered by movement_data are included in the network.

Value

An igraph object consisting of a directed static network, with nodes representing holdings, and edges representing moves between holdings. Additionally, information is printed out about the constructed network; this output is passed on from igraph::graph_from_data_frame(), the meaning of all elements is explained in igraph::igraph.

Details

Any movement_data columns beyond from and to are set as edge attributes in the network, and any holding_data columns beyond id are set as node attributes.

See also

Other network-related functions: create_temporal_network_analysis_report(), movedata2networkDynamic(), parallel_summarise_temporal_node_properties(), trace_contact_chains()

Examples

movement_data <- head(example_movement_data, 20)
holding_data <- head(example_holding_data, 20)

# Create a network using only movement_data
movedata2igraph(movement_data)
#> IGRAPH 1bc47af DN-- 40 20 -- 
#> + attr: name (v/c), departure_date (e/n), qty_pigs (e/n),
#> | movement_reference (e/n)
#> + edges from 1bc47af (vertex names):
#>  [1] 95/216/1100->19/818/9098 69/196/5890->71/939/3228 52/577/5349->82/501/8178
#>  [4] 39/103/5541->13/282/1763 41/788/6464->57/418/6011 69/393/9398->39/947/2201
#>  [7] 17/219/5051->56/606/9225 10/610/5301->44/417/1954 44/560/4357->23/365/6095
#> [10] 53/544/5452->21/648/8446 57/961/5592->50/311/4527 95/435/2021->59/623/8252
#> [13] 75/855/4236->27/193/6339 35/429/8304->33/797/1580 88/816/6821->59/776/4403
#> [16] 68/366/6490->51/634/2655 48/368/5275->77/857/9849 81/124/5621->51/394/2823
#> [19] 84/613/2906->71/747/6459 99/551/3187->86/302/7610

# Create a network using movement_data and holding_data, including only
# active holdings
movedata2igraph(movement_data, holding_data,
                incl_nonactive_holdings = FALSE)
#> IGRAPH 1bc82a8 DN-- 40 20 -- 
#> + attr: name (v/c), holding_type (v/c), herd_size (v/n), coordinates
#> | (v/x), departure_date (e/n), qty_pigs (e/n), movement_reference (e/n)
#> + edges from 1bc82a8 (vertex names):
#>  [1] 95/216/1100->19/818/9098 69/196/5890->71/939/3228 52/577/5349->82/501/8178
#>  [4] 39/103/5541->13/282/1763 41/788/6464->57/418/6011 69/393/9398->39/947/2201
#>  [7] 17/219/5051->56/606/9225 10/610/5301->44/417/1954 44/560/4357->23/365/6095
#> [10] 53/544/5452->21/648/8446 57/961/5592->50/311/4527 95/435/2021->59/623/8252
#> [13] 75/855/4236->27/193/6339 35/429/8304->33/797/1580 88/816/6821->59/776/4403
#> [16] 68/366/6490->51/634/2655 48/368/5275->77/857/9849 81/124/5621->51/394/2823
#> [19] 84/613/2906->71/747/6459 99/551/3187->86/302/7610

# Create a network using movement_data and holding_data, including both
# active and non-active holdings
movedata2igraph(movement_data, holding_data,
                incl_nonactive_holdings = TRUE)
#> IGRAPH 1bca8d1 DN-- 57 20 -- 
#> + attr: name (v/c), holding_type (v/c), herd_size (v/n), coordinates
#> | (v/x), departure_date (e/n), qty_pigs (e/n), movement_reference (e/n)
#> + edges from 1bca8d1 (vertex names):
#>  [1] 95/216/1100->19/818/9098 69/196/5890->71/939/3228 52/577/5349->82/501/8178
#>  [4] 39/103/5541->13/282/1763 41/788/6464->57/418/6011 69/393/9398->39/947/2201
#>  [7] 17/219/5051->56/606/9225 10/610/5301->44/417/1954 44/560/4357->23/365/6095
#> [10] 53/544/5452->21/648/8446 57/961/5592->50/311/4527 95/435/2021->59/623/8252
#> [13] 75/855/4236->27/193/6339 35/429/8304->33/797/1580 88/816/6821->59/776/4403
#> [16] 68/366/6490->51/634/2655 48/368/5275->77/857/9849 81/124/5621->51/394/2823
#> [19] 84/613/2906->71/747/6459 99/551/3187->86/302/7610

rm(movement_data, holding_data)