Plot a diagram (directed graph) of top linkages

plotLinks(top_links_dt, wiot, units = list(units_suffix = "bn USD",
  mln_USD_exchange_rate = 0.001),
  country_labels_dt = wiod.diagrammer::countries(),
  sector_labels_dt = wiod.diagrammer::sectors(wiot),
  aggregates_dt = wiod.diagrammer::aggregates(wiot),
  arrowSizeFun = function(value) wiod.diagrammer:::normalise(value) * 16 + 1,
  arrowLabelFun = identity, nodeSizeFun = function(country_sector_dt)
  country_sector_dt %>% ifelse.(.$isFinal, .$II_fob, .$GO),
  nodeSizeTransformFun = function(node_size_val)
  wiod.diagrammer::normalise(log(node_size_val) + 1) * 8 + 8,
  nodeLabelFun = function(country_sector_dt) country_sector_dt %>%
  paste.(.$CountryLab, .$SectorLab, paste(.$NodeSize %>% numberFormattingFun,
  units$units_suffix), sep = ", "),
  specificNodeOptionsFun = function(country_sector_dt)
  ifelse(country_sector_dt$isFinal, "fontname=\"times-italic\"", ""),
  specificArrowOptionsFun = function(top_links_dt)
  ifelse(top_links_dt$ExpCountry == top_links_dt$ImpCountry, "style=solid",
  "style=dashed"), general_arrow_options = "color=grey",
  general_node_options = "shape=box", graph_options = c("layout=dot",
  "rankdir=LR"), numberFormattingFun = function(value) value %>%
  formatC(digits = 1, format = "f", big.mark = " "), nchar_wrap = 30,
  gvcode = FALSE)

Arguments

top_links_dt

A data.table returned by findLinks

wiot

WIOD data.table returned by loadWIOD

units

Optional: a list of two named interrelated elements:

units_suffix

a string (character vector of length 1) with a name of the monetary units (default: "bn USD"). This element should be consistent with the next element mln_USD_exchange_rate!

mln_USD_exchange_rate

a single value (numeric vector of length 1) by which the original WIOD numbers (which are in million US dollars) will be multiplied (default: 0.001, so that the values become billion US dollars). This element should be consistent with the previous element units_suffix!

country_labels_dt

Optional: a data.table with specific columns -- see the documentation for countries which is the function called to produce the default value for country_labels_dt. With this data.table, you may provide alternative (non-default) country names/labels and/or additional country-level variables (columns) to be used by your (i.e. non-default) functions for the arguments nodeSizeFun, nodeLabelFun, and specificNodeOptionsFun.

sector_labels_dt

Optional: a data.table with specific columns -- see the documentation for sectors which is the function called to produce the default value for country_labels_dt With this data.table, you may provide alternative (non-default) sector names/labels and/or additional sector-level variables (columns) to be used by your (i.e. non-default) functions for the arguments nodeSizeFun, nodeLabelFun, and specificNodeOptionsFun.

aggregates_dt

Optional: a data.table with specific columns -- see the documentation for aggregates which is the function called to produce the default value for aggregates_dt. With this data.table, you may provide additional or alternative country-and-sector-level variables (columns) to be used by your (i.e. non-default) functions for the arguments nodeSizeFun, nodeLabelFun, and specificNodeOptionsFun.

arrowSizeFun

Optional: a one-numeric-argument function which translates top_links_dt's value column into GraphViz's penwidth values for arrows (edges), see http://www.graphviz.org/content/attrs#dpenwidth).

arrowLabelFun

Optional: a one-numeric-argument function which translates top_links_dt's value column (multiplied by units$mln_USD_exchange_rate, transformed by the numberFormattingFun function, and with units_suffix pasted) into GraphViz's labels for arrows (edges). Default: identity.

nodeSizeFun

Optional: a function which takes a country-and-sector level data.table (including the columns of aggregates_dt) and returns a numeric vector representing the sizes of the country-sector nodes (boxes). Default: the value of 'output at basic prices' (GO) for the industrial sectors (i.e. those that produce something -- goods or services) and 'total intermediate consumption' (II_fob) for the final use sectors

nodeSizeTransformFun

Optional: a one-argument function which takes the numeric value returned by the function nodeSizeFun and translates it into GraphViz's fontsize values for the country-sector nodes (boxes), see http://www.graphviz.org/content/attrs#dfontsize).

nodeLabelFun

Optional: a function which takes the country-and-sector-level data.table -- a merger of aggregates_dt, country_labels_dt, and sector_labels_dt for the country-sector combinations present in top_links_dt -- and returns a character vector used as GraphViz's labels for nodes (boxes). If the function needs to refer to the node size (produced by the function nodeSizeFun) it should refer to data.table's column NodeSize. Default: it returns, for each node, the following components pasted together: country label, sector label, a value returned by nodeSizeFun and the units$units_suffix.

specificNodeOptionsFun

Optional: a function which takes the country-and-sector-level data.table and returns a character vector of GraphViz's node atributes*, see ** with 'node' highlighted in the 'COMPONENTS' section. Default: 'fontname="times-italic"' for the final use sectors (such as final consumption or investment).

specificArrowOptionsFun

Optional: a function which takes top_links_dt as an argument and returns a character vector of GraphViz's edge atributes*, see ** with 'edge' highlighted in the 'COMPONENTS' section. Default: 'style=solid' for the domestic flows and 'style=dashed' for the international flows.

general_arrow_options

Optional: a character constant (vector of length 1) with the GraphViz's edge global atributes* of all the arrows (edges) see ** with 'edge' highlighted in the 'COMPONENTS' section. . Default: 'color=grey'.

general_node_options

Optional: a character constant (vector of length 1) with the GraphViz's edge global atributes* of all the nodes (country-sector boxes) see ** with 'node' highlighted in the 'COMPONENTS' section. Default: 'shape=box'.

graph_options

Optional: character constant (vector of length 1) with the GraphViz's edge global atributes* of the whole graph. See ** with 'graph' highlighted in the 'COMPONENTS' section. Default: c('layout=dot', 'rankdir=LR'). For the 'layout' see https://en.wikipedia.org/wiki/Graphviz#Software_architecture; 'rankdir' is applicable only if 'layout=dot', LR = left-to-right, TB = top-to-bottom.

numberFormattingFun

Optional: a one-numeric-argument function used to format all the numbers displayed in the graph. Default: it returns a character vector with values formated as one digit after decimal dot and blank as a digit-grouping separator.

nchar_wrap

Optional: a numeric constant -- the number of characters arounnd which the text of arrow labels (returned by arrowLabelFun) is wraped into another line. Default: 30.

gvcode

Optional: should the generated GraphViz code be returned instead of the grViz object (logical)? This is useful for debugging. Default: FALSE.

Value

The return value of grViz or the Graphviz code if gvcode = TRUE.

Footnotes

* in the form of comma-separate key=value pairs: 'attribute_name_1 = attribute_value_1, attribute_name_2 = attribute_value_2, ...'

** http://www.graphviz.org/doc/schema/attributes.xml