Creates a community-aware network plot in which each community is shown as a circular bubble, with its vertices laid out inside the bubble. Community centres are positioned using a graph layout and subsequently separated to prevent bubbles from overlapping. Larger communities therefore occupy more space in the overall layout.

plot_community_bubbles(
  g,
  comm = igraph::cluster_infomap(g),
  layout = "fr",
  inside_layout = "external_fr",
  external_measure = "count",
  direction = "both",
  node_size = NULL,
  node_title = NULL,
  node_size_ranges = c(4, 16),
  node_size_color = FALSE,
  edge_width = NULL,
  edge_opacity_multiplier = 1,
  edge_title = NULL,
  label_card = TRUE,
  nudge_label = c(-0.1, -0.3),
  text_size = 4.5,
  text_face = "plain",
  bubble_scale = 1,
  node_spacing = 1,
  bubble_gap = 1,
  centre_iterations = 100,
  node_clouds = FALSE,
  cloudiness = 2,
  show_bubbles = TRUE,
  fill_bubble = TRUE,
  plot_margin = margin(0, 15, 0, 0),
  legend_position = NULL,
  community_legend = TRUE,
  size_legend = TRUE,
  edge_legend = TRUE
)

Arguments

g

An igraph graph object.

comm

Community membership, either an igraph communities object or a vector with one community ID per vertex. Defaults to igraph::cluster_infomap().

layout

Layout used for community centres. Supported values include "fr", "kk", "circle", "drl", "lgl", "graphopt", and "nicely", or a user-supplied layout function.

inside_layout

Layout used within each community: "circle", "external", "fr", or "external_fr".

external_measure

How external connectivity is measured: "count" counts external edges, while "weighted" sums their weights.

direction

For directed graphs, whether external connectivity is based on "both", "out", or "in" edges.

node_size

Optional vertex attribute name used to scale node size.

node_title

Optional title for node sizing on the legend.

node_size_ranges

Range within which to scale the nodes using node_size. (Default c(4, 16))

node_size_color

Display node size with a monochrome colorbar (Default FALSE)

edge_width

Optional edge attribute name used to scale edge width.

edge_opacity_multiplier

Tweak opacity of edges by a multiplier. (any float, Default 1 for no tweak, 0 for transparent, 2 for doubling opacity)

edge_title

Optional title for edge scale on the legend.

label_card

Enable a card behind the label for visibility (Default TRUE)

nudge_label

Nudge in position of label from node (Default c(-0.1, -0.3))

text_size

Set text size on labels (Default 4.5)

text_face

Set text type on labels as passed to ggraph::geom_node_label (Default "plain")

bubble_scale

Numeric multiplier controlling bubble size.

node_spacing

Numeric multiplier controlling spacing of vertices within bubbles.

bubble_gap

Minimum gap between community bubbles.

centre_iterations

Number of iterations used to resolve overlapping community bubbles.

node_clouds

Enable community colored clouds around nodes (Default FALSE)

cloudiness

Intensity of community representing clouds drawn around a node.

show_bubbles

Enable drawing of bubble backdrop for communities (Default TRUE)

plot_margin

Margins passed to ggplot2::theme. (Default margin(0, 15, 0, 0))

legend_position

Legend position parameter passed to ggplot2::theme(). (Default NULL, compute legend position)

community_legend

Enable color legend for communities (Default: TRUE)

size_legend

Enable size legend for node sizes (Default: TRUE)

edge_legend

Enable edge legend fo edge widths (Default: TRUE)

fill_bubbles

Enable filling bubble with shade corresponding to communtiy (Default TRUE)

Value

A ggraph/ggplot object.

Details

Several layouts are available for vertices within communities. "circle" places vertices evenly around the bubble, "fr" uses a force-directed layout, and "external" places vertices according to their connectivity to other communities. "external_fr" combines the latter with the angular structure of a force-directed layout. In the external layouts, vertices with many or strong connections outside their community are placed closer to the community centre, highlighting potential inter-community bridges.

External connectivity can be based on edge counts or edge weights, and can account for incoming, outgoing, or both types of connections in directed graphs.

Certain data like node sizes, node names etc are passed on as igraph vertex attributes in g. The names of these attributes are then passed via parameters like node_size or edge_width as strings. Some attribute names are used automatically if they exist (like name)

The name vertex attribute is used for producing labels for each vertex. Plots with and witout labels are both automatically produced.

The graph is represented at two levels. First, communities are contracted into a community-level graph whose vertices are laid out using layout. Community centres are then iteratively separated according to their bubble radii, preserving the broad structure of the selected layout while preventing overlap.

For "external" and "external_fr", each vertex receives an external-connectivity score based on edges connecting it to other communities. The score is normalized within each community and controls the vertex's radial position: highly externally connected vertices are drawn near the centre, while vertices with predominantly internal connections are placed toward the perimeter.