Skip to contents

Visualizes agent behaviors in a network using ggnetwork. Accepts a Trial or AgentBasedModel and colors nodes by behavior.

Usage

plot_network_adoption(
  x,
  layout = NULL,
  behaviors = c("Adaptive", "Legacy"),
  behavior_colors = SOCMOD_PALETTE[c(2, 1)],
  node_size = 6,
  label = FALSE,
  plot_mod = identity,
  edgewidth = 1
)

Arguments

x

A Trial or AgentBasedModel.

behaviors

Behavior levels. Default: c("Adaptive", "Legacy").

behavior_colors

Color palette. Default: first 2 of SOCMOD_PALETTE.

node_size

Single number or named list (e.g. list(Degree = igraph::degree)).

label

Whether to show node labels. Default: TRUE.

plot_mod

A function to modify the ggplot object. Default: identity.

Value

A ggplot object.

Examples

trial <- example_trial()
#> Error in example_trial(): could not find function "example_trial"
plot_network_adoption(trial)
#> Error: object 'trial' not found

# Use degree centrality to size nodes
plot_network_adoption(trial, node_size = list(Degree = igraph::degree))
#> Error: object 'trial' not found

# Add a title and modify legend position
plot_network_adoption(
  trial,
  plot_mod = . %>%
    ggtitle("Adoption at t = 0") %>%
    theme(legend.position = "bottom")
)
#> Error: object 'trial' not found

# Specify a circular layout
plot_network_adoption(make_abm(graph = make_small_world(10, 4, 0.2)), layout = "circle")
#> Error in layout$args: $ operator is invalid for atomic vectors