Skip to contents

Creates a simple graphical representation of a trophic network using ggplot2.

Usage

# S3 method for class 'trophic_tbl'
plot(
  x,
  shift = TRUE,
  colors = NULL,
  edge_width = c("none", "raw", "norm_target", "norm_source"),
  ...
)

Arguments

x

A trophic_tbl object.

shift

To shift x_axis between trophic level and avoid the potential overlapping of arrows.

colors

A named character vector of colors (hexadecimal or standard R color names) where the names match the node names in the trophic table. If NULL, default ggplot2 colors are used.

edge_width

A character string indicating how to scale the width of the arrows. Must be one of "none" (default), "raw" (uses the raw weights), "norm_target" (normalizes weights to sum to 1 for each target/to node), or "norm_source" (normalizes weights to sum to 1 for each source/from node).

...

Additional arguments (not used, for S3 consistency).

Value

A ggplot object.

Details

Nodes are positioned according to their trophic level:

  • The y-axis represents trophic levels

  • Nodes of the same level are placed on the same horizontal line

  • The x-axis positions are assigned sequentially (0, 1, 2, ...)

Directed links are drawn from lower to higher trophic levels using arrows.

Examples

net <- trophic() |>
  add_link("a", "b") |>
  add_link("b", "c")

# Plot with default colors
plot(net)


# Plot with custom colors
my_pal <- c("a" = "brown", "b" = "green", "c" = "blue")
plot(net, colors = my_pal)