plot_troph_level_ggplot: Plot an Ecological Network Organized by Trophic Level

View source: R/plotNetworkGgplot.R

plot_troph_level_ggplotR Documentation

Plot an Ecological Network Organized by Trophic Level

Description

This function visualizes a food web using ggplot2, where nodes represent species and edges represent interactions. Nodes are positioned by trophic level on the y-axis, and optionally, community modules on the x-axis.

Usage

plot_troph_level_ggplot(
  g,
  vertexSizeFactor = 5,
  vertexSizeMin = 5,
  modules = FALSE,
  weights = NA,
  community_obj = NULL,
  maxTL = NULL,
  use_numbers = FALSE,
  label_size = 4,
  arrow_size = 0.15,
  shorten_factor = 0.005
)

Arguments

g

An igraph object representing the ecological network.

vertexSizeFactor

Numeric factor to determine node size based on degree (default: 5).

vertexSizeMin

Numeric value for the minimum node size (default: 5).

modules

Logical; if TRUE, nodes are grouped by community modules detected using cluster_spinglass() (default: FALSE).

weights

A numeric vector, NULL, or NA, specifying edge weights for community detection. If NULL, the function uses the weight attribute of g if available. If NA, weights are ignored (default: NA).

community_obj

An optional community detection object. If NULL, the function calculates modules automatically (default: NULL).

maxTL

Numeric, maximum trophic level to display on the y-axis. If NULL, it is determined automatically (default: NULL).

use_numbers

Logical; if TRUE, nodes are labeled with numeric IDs instead of species names to reduce label overlap in large networks (default: FALSE).

label_size

Numeric, font size for node labels (default: 4).

arrow_size

Numeric, size of the arrowheads for directed edges (default: 0.15).

shorten_factor

Numeric, a small factor to adjust arrow placement by slightly shortening edges. This prevents arrowheads from overlapping with node centers. A small positive value (e.g., 0.005) works well (default: 0.005).

Value

A ggplot object visualizing the trophic structure of the network. If use_numbers = TRUE, it also returns a tibble mapping numeric labels to species names.

Examples


g <- netData$Angola
plot_troph_level_ggplot(g, modules = TRUE, use_numbers = TRUE)



lsaravia/EcoNetwork documentation built on April 5, 2025, 1:51 p.m.