Pass a data frame containing a group-to-group query and return a network plot. Automatically handles "Collaborators_within_group" and "Other_collaborators" within query data.

network_g2g(
  data,
  time_investor = NULL,
  collaborator = NULL,
  metric = "Collaboration_hours",
  algorithm = "fr",
  node_colour = "lightblue",
  exc_threshold = 0.1,
  org_count = NULL,
  subtitle = "Collaboration Across Organizations",
  return = "plot"
)

g2g_network(
  data,
  time_investor = NULL,
  collaborator = NULL,
  metric = "Collaboration_hours",
  algorithm = "fr",
  node_colour = "lightblue",
  exc_threshold = 0.1,
  org_count = NULL,
  subtitle = "Collaboration Across Organizations",
  return = "plot"
)

Arguments

data

Data frame containing a G2G query.

time_investor

String containing the variable name for the Time Investor column.

collaborator

String containing the variable name for the Collaborator column.

metric

String containing the variable name for metric. Defaults to Collaboration_hours.

algorithm

String to specify the node placement algorithm to be used. Defaults to "fr" for the force-directed algorithm of Fruchterman and Reingold. See https://rdrr.io/cran/ggraph/man/layout_tbl_graph_igraph.html for a full list of options.

node_colour

String or named vector to specify the colour to be used for displaying nodes. Defaults to "lightblue".

  • If "vary" is supplied, a different colour is shown for each node at random.

  • If a named vector is supplied, the names must match the values of the variable provided for the time_investor and collaborator columns. See example section for details.

exc_threshold

Numeric value between 0 and 1 specifying the exclusion threshold to apply. Defaults to 0.1, which means that the plot will only display collaboration above 10% of a node's total collaboration. This argument has no impact on "data" or "table" return.

org_count

Optional data frame to provide the size of each organization in the collaborator attribute. The data frame should contain only two columns:

  • Name of the collaborator attribute excluding any prefixes, e.g. "Organization". Must be of character or factor type.

  • "n". Must be of numeric type. Defaults to NULL, where node sizes will be fixed.

subtitle

String to override default plot subtitle.

return

String specifying what to return. This must be one of the following strings:

  • "plot"

  • "table"

  • "network"

  • "data"

See Value for more information.

Value

A different output is returned depending on the value passed to the return

argument:

  • "plot": 'ggplot' object. A group-to-group network plot.

  • "table": data frame. An interactive matrix of the network.

  • "network: 'igraph' object used for creating the network plot.

  • "data": data frame. A long table of the underlying data.

Examples

# Return a network plot
g2g_data %>% network_g2g()
#> `time_investor` field not provided. Assuming `TimeInvestors_Organization` as the `time_investor` variable.
#> `collaborator` field not provided. Assuming `Collaborators_Organization` as the `collaborator` variable.


# Return a network plot - Meeting hours and 5% threshold
g2g_data %>%
  network_g2g(time_investor = "TimeInvestors_Organization",
              collaborator = "Collaborators_Organization",
              metric = "Meeting_hours",
              exc_threshold = 0.05)


# Return a network plot - custom-specific colours
# Get labels of orgs and assign random colours
org_str <- unique(g2g_data$TimeInvestors_Organization)

col_str <-
  sample(
    x = c("red", "green", "blue"),
    size = length(org_str),
    replace = TRUE
  )

# Create and supply a named vector to `node_colour`
names(col_str) <- org_str

g2g_data %>%
  network_g2g(node_colour = col_str)
#> `time_investor` field not provided. Assuming `TimeInvestors_Organization` as the `time_investor` variable.
#> `collaborator` field not provided. Assuming `Collaborators_Organization` as the `collaborator` variable.



# Return a network plot with circle layout
# Vary node colours and add org sizes
org_tb <- hrvar_count(
  sq_data,
  hrvar = "Organization",
  return = "table"
)

g2g_data %>%
  network_g2g(algorithm = "circle",
              node_colour = "vary",
              org_count = org_tb)
#> `time_investor` field not provided. Assuming `TimeInvestors_Organization` as the `time_investor` variable.
#> `collaborator` field not provided. Assuming `Collaborators_Organization` as the `collaborator` variable.


# Return an interaction matrix
# Minimum arguments specified
g2g_data %>%
  network_g2g(return = "table")
#> `time_investor` field not provided. Assuming `TimeInvestors_Organization` as the `time_investor` variable.
#> `collaborator` field not provided. Assuming `Collaborators_Organization` as the `collaborator` variable.
#> # A tibble: 16 × 17
#>    TimeInvest…¹ Biz D…²      CEO Custo…³ Facil…⁴ Finan…⁵ Finan…⁶ Finan…⁷ Finan…⁸
#>    <chr>          <dbl>    <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>
#>  1 Biz Dev      0.494    2.82e-4 0.00181 0.00170 0.00178 0.00237 0.00222 0.00212
#>  2 CEO          0.0419  NA       0.0599  0.0720  0.0564  0.0528  0.0757  0.0558 
#>  3 Customer Se… 0.00150  5.69e-4 0.502   0.00225 0.00174 0.00235 0.00178 0.00195
#>  4 Facilities   0.00148  4.52e-4 0.00189 0.489   0.00223 0.00211 0.00160 0.00220
#>  5 Finance-Cor… 0.00178  4.14e-4 0.00213 0.00287 0.500   0.00223 0.00205 0.00230
#>  6 Finance-East 0.00182  3.76e-4 0.00207 0.00180 0.00177 0.468   0.00206 0.00190
#>  7 Finance-Sou… 0.00214  6.47e-4 0.00173 0.00167 0.00177 0.00265 0.465   0.00204
#>  8 Finance-West 0.00166  2.94e-4 0.00188 0.00180 0.00166 0.00188 0.00177 0.479  
#>  9 Financial P… 0.00220  4.95e-4 0.00225 0.00193 0.00223 0.00265 0.00167 0.00185
#> 10 G&A Central  0.00163  2.79e-4 0.00201 0.00213 0.00179 0.00263 0.00289 0.00208
#> 11 G&A East     0.00172  7.24e-4 0.00179 0.00161 0.00172 0.00209 0.00164 0.00168
#> 12 G&A South    0.0506   4.42e-4 0.0588  0.0577  0.0523  0.0652  0.0592  0.0689 
#> 13 Human Resou… 0.0481   2.02e-4 0.0581  0.0560  0.0529  0.0663  0.0626  0.0651 
#> 14 IT-Corporate 0.0525   3.80e-4 0.0569  0.0571  0.0529  0.0658  0.0618  0.0684 
#> 15 IT-East      0.0502   4.78e-4 0.0603  0.0584  0.0542  0.0665  0.0665  0.0708 
#> 16 Inventory M… 0.0485   5.10e-4 0.0561  0.0591  0.0498  0.0648  0.0593  0.0629 
#> # … with 8 more variables: `Financial Planning` <dbl>, `G&A Central` <dbl>,
#> #   `G&A East` <dbl>, `G&A South` <dbl>, `Human Resources` <dbl>,
#> #   `IT-Corporate` <dbl>, `IT-East` <dbl>, `Inventory Management` <dbl>, and
#> #   abbreviated variable names ¹​TimeInvestorOrg, ²​`Biz Dev`,
#> #   ³​`Customer Service`, ⁴​Facilities, ⁵​`Finance-Corporate`, ⁶​`Finance-East`,
#> #   ⁷​`Finance-South`, ⁸​`Finance-West`