network_p2p {wpa} | R Documentation |
Perform network analysis with the person-to-person query
Description
Analyse a person-to-person (P2P) network query, with multiple visualisation and analysis output options. Pass a data frame containing a person-to-person query and return a network visualization. Options are available for community detection using either the Louvain or the Leiden algorithms.
Usage
network_p2p(
data,
hrvar = "Organization",
return = "plot",
centrality = NULL,
community = NULL,
weight = NULL,
comm_args = NULL,
layout = "mds",
path = paste("p2p", NULL, sep = "_"),
style = "igraph",
bg_fill = "#FFFFFF",
font_col = "grey20",
legend_pos = "right",
palette = "rainbow",
node_alpha = 0.7,
edge_alpha = 1,
edge_col = "#777777",
node_sizes = c(1, 20),
seed = 1
)
Arguments
data |
Data frame containing a person-to-person query. |
hrvar |
String containing the label for the HR attribute. |
return |
A different output is returned depending on the value passed to the
|
centrality |
string to determines which centrality measure is used to
scale the size of the nodes. All centrality measures are automatically
calculated when it is set to one of the below values, and reflected in the
When |
community |
String determining which community detection algorithms to apply. Valid values include:
These values map to the community detection algorithms offered by |
weight |
String to specify which column to use as weights for the
network. To create a graph without weights, supply |
comm_args |
list containing the arguments to be passed through to igraph's clustering algorithms. Arguments must be named. See examples section on how to supply arguments in a named list. |
layout |
String to specify the node placement algorithm to be used.
Defaults to |
path |
File path for saving the PDF output. Defaults to a timestamped path based on current parameters. |
style |
String to specify which plotting style to use for the network plot. Valid values include:
|
bg_fill |
String to specify background fill colour. |
font_col |
String to specify font colour. |
legend_pos |
String to specify position of legend. Defaults to
|
palette |
String specifying the function to generate a colour palette
with a single argument |
node_alpha |
A numeric value between 0 and 1 to specify the transparency of the nodes. Defaults to 0.7. |
edge_alpha |
A numeric value between 0 and 1 to specify the transparency of the edges (only for 'ggraph' mode). Defaults to 1. |
edge_col |
String to specify edge link colour. |
node_sizes |
Numeric vector of length two to specify the range of node
sizes to rescale to, when |
seed |
Seed for the random number generator passed to either
|
Value
A different output is returned depending on the value passed to the return
argument:
-
'plot'
: return a network plot, interactively within R. -
'plot-pdf'
: save a network plot as PDF. This option is recommended when the graph is large, which make take a long time to run ifreturn = 'plot'
is selected. Use this together withpath
to control the save location. -
'sankey'
: return a sankey plot combining communities and HR attribute. This is only valid if a community detection method is selected atcommunity
. -
'table'
: return a vertex summary table with counts in communities and HR attribute. Whencentrality
is non-NULL, the average centrality values are calculated per group. -
'data'
: return a vertex data file that matches vertices with communities and HR attributes. -
'network'
: return 'igraph' object.
See Also
Other Network:
external_network_plot()
,
g2g_data
,
internal_network_plot()
,
network_describe()
,
network_g2g()
,
network_summary()
,
p2p_data_sim()
Examples
p2p_df <- p2p_data_sim(dim = 1, size = 100)
# default - ggraph visual
network_p2p(data = p2p_df, style = "ggraph")
# return vertex table
network_p2p(data = p2p_df, return = "table")
# return vertex table with community detection
network_p2p(data = p2p_df, community = "leiden", return = "table")
# leiden - igraph style with custom resolution parameters
network_p2p(data = p2p_df, community = "leiden", comm_args = list("resolution" = 0.1))
# louvain - ggraph style, using custom palette
network_p2p(
data = p2p_df,
style = "ggraph",
community = "louvain",
palette = "heat_colors"
)
# leiden - return a sankey visual with custom resolution parameters
network_p2p(
data = p2p_df,
community = "leiden",
return = "sankey",
comm_args = list("resolution" = 0.1)
)
# using `fluid_communities` algorithm with custom parameters
network_p2p(
data = p2p_df,
community = "fluid_communities",
comm_args = list("no.of.communities" = 5)
)
# Calculate centrality measures and leiden communities, return at node level
network_p2p(
data = p2p_df,
centrality = "betweenness",
community = "leiden",
return = "data"
) %>%
dplyr::glimpse()