plotweb: Visualize a bipartite interaction matrix (e.g. a foodweb)

View source: R/plotweb.R

plotwebR Documentation

Visualize a bipartite interaction matrix (e.g. a foodweb)

Description

This is the help file for the new plotweb implementation. For help with the old, deprecated plotweb function see plotweb_deprecated.

A more in depth guide on how to use this function to plot biparitte networks with multiple visual examples is given in the vignette PlottingWithBipartite.

A two dimensional matrix is plotted as a bipartite graph.

Usage

plotweb(web,
        sorting = "normal",
        empty = FALSE,
        higher_abundances = NULL,
        lower_abundances = NULL,
        add_higher_abundances = NULL,
        add_lower_abundances = NULL,
        higher_labels = NULL,
        lower_labels = NULL,
        scaling = "relative",
        font = NULL,
        family = NULL,
        srt = 0,
        higher_italic = FALSE,
        lower_italic = FALSE,
        text_size = "auto",
        spacing = 0.3,
        box_size = 0.1,
        x_lim = c(0, 1),
        y_lim = c(0, 1),
        lab_distance = 0.05,
        lower_color = "black",
        lower_border = "same",
        lower_add_color = "red",
        lower_text_color = "black",
        higher_color = "black",
        higher_border = "same",
        higher_add_color = "red",
        higher_text_color = "black",
        horizontal = FALSE,
        link_color = "higher",
        link_border = "same",
        link_alpha = 0.5,
        curved_links = FALSE,
        arrow = "no",
        plot_axes = FALSE,
        add = FALSE,
        mar = c(1, 1, 1, 1),
        mai = NULL)

Arguments

web

Web is a matrix representing the interactions observed between higher trophic level species (columns) and lower trophic level species (rows). Usually this will be number of pollinators on each species of plants or number of parasitoids on each species of prey.

sorting

Sorting option passed to the sortweb function. The default "normal" doesn't reorder the web.

empty

If TRUE empty columns and rows are removed from the web.

higher_abundances

Vector with independent abundance estimates for the higher trophic level, NULL if none exist. See Notes!

lower_abundances

Vector with independent abundance estimates for the lower trophic level, NULL if none exist. See Notes!

add_higher_abundances

Vector with additional abundances (e.g. unparasitised hosts) for the higher trophic level, NULL if none exist. See Notes!

add_lower_abundances

Vector with additional abundances (e.g. unparasitised hosts) for the lower trophic level, NULL if none exist. See Notes!

higher_labels

Boolean or named list. Indicating whether the higher labels should be plotted. Named list may be used for abbrevations or partly cursive labels.

lower_labels

Boolean or named list. Indicating whether the lower labels should be plotted. Named list may be used for abbrevations or partly cursive labels.

scaling

Choice of either "relative" or "absoulte". For more information see Scaling.

font

An integer which specifies which font to use for the labels. See par.

family

The name of a font family for drawing the labels. See par.

srt

Orientation of the labels in degrees. (Default: 0)

text_size

Factor by which the size of the label text should be scaled. Values < 1 makes them smaller, values > 1 makes them greater. (Default: "auto")

spacing

Either "auto", a single value or a numerical vector of the form c(higher, lower). Defines the total space between boxes. See Notes! (Default: 0.3)

plot_axes

Indicates whether both axes should be drawn on the plot. (Default: FALSE)

box_size

Size of the boxes. Numerical with either c(higher_box_size, lower_box_size) or one value if both should be the same. (Default: 0.1)

higher_italic

If set to TRUE, the labels of the higher species are plotted in italics. (Default: FALSE)

lower_italic

If set to TRUE, the labels of the lower species are plotted in italics. (Default: FALSE)

x_lim

Vector with 2 numerical values. The range in which to plot on the x-axis. (Default: c(0, 1))

y_lim

Vector with 2 numerical values. The range in which to plot on the y-axis. (Default: c(0, 1))

lab_distance

Distance between the boxes and the labels in inches

higher_color

A single color or a list of colors used to plot the higher species (columns) boxes. (Default: "black")

higher_border

Either "same" or a single color or a list of colors used to plot the higher species (columns) boxes borders. If "same", the borders have the same color as the corresponding boxes.

higher_add_color

Only used when higher additional abundances are defined. A single color or a list of colors used to plot the higher (column) additional boxes. (Default: "red")

higher_text_color

A single color or a list of colors used to plot the lower species (rows) labels. (Default: "black")

lower_color

A single color or a list of colors used to plot the lower species (rows) boxes. (Default: "black")

lower_border

Either "same" or a single color or a list of colors used to plot the lower species (rows) boxes borders. If "same", the borders have the same color as the corresponding boxes.

lower_add_color

Only used when lower additional abundances are defined. A single color or a list of colors used to plot the lower (row) additional boxes. (Default: "red")

lower_text_color

A single color or a list of colors used to plot the lower species (rows) labels. (Default: "black")

horizontal

Boolean indicating whether the connection between the boxes and the label texts should be plotted horizontally. (Default: FALSE)

link_color

"lower", "higher", or single color value. If "lower" or "higher" the link color is taken from the corresponding lower or higher box. Otherwise all links have the defined color. (Default: "higher")

link_border

Either "same" or a single color or a list of colors used to plot the link borders. If "same", the borders have the same color as the corresponding boxes.

link_alpha

Number between 0.0 and 1.0 setting the transparency of the links. 0 means full transparency 1 means full opacity. (Default: 0.5)

curved_links

If FALSE links are plotted as straight lines otherwise they are curved. (Default: FALSE)

arrow

Display type of connection between higher and lower boxes, options are

  • "no" (Default)

  • "up"

  • "down"

  • "both"

  • "up.center"

  • "down.center"

  • "both.center"

add

If set to TRUE a new bipartite network plot is added to the previous plot. (Default: FALSE)

mar

A numerical vector of the form c(bottom, left, top, right) which gives the number of lines of margin to be specified on the four sides of the plot. The default is NULL which takes the global setting from par().

mai

A numerical vector of the form c(bottom, left, top, right) which gives the margin size specified in inches. Please note, that the margin is increased so that the labels are always visible in the plot.

Value

Returns a window with a bipartite graph of the given web.

Text size & Spacing

The "auto" text_size or spacing option can be very handy for quickly creating a plot. However in certain cases it might not produce the best results. Especially in cases where there are plenty species with rather long names or multiple species with low abundances, the labels can tend to overlap. In those cases defining the spacing and text_size manually or rotating the labels with the srt argument might produce better results.

Special care must be taken if two different values are passed to the argument for the higher and lower species. The total size of the boxes will not be comparable between the sides in that case. So especially using the argument scaling = "absolute" might not yield the intended result.

Abundances

Both independent as well as additional abundances should be passed as a named vector.

If no independent abundances are given the row and column sums are used to calculate the size of the boxes.

Scaling

The scaling option is only relevant, if either independent or additional or both have been defined.

In case "relative" is selected the boxes of higher and lower abundances are scaled so that they both utilize the whole space.

In case "absolute" is selected only the boxes of the side with the higher total abundances uses the full space the other side is then scaled relatively to that side. So that species with the same abundance are plotted with boxes of the same size.

Be extra careful about the spacing option when using "absolute" scaling.

Note

Note the difference between relative and absolute scaling is mainly important in the case either additional or independent abundances have been defined. In case relative is selected the boxes of higher and lower abundances are scaled so that they both utilize the whole space. In case absolute is selected only the boxes of the side with the higher total abundances uses the full space the other side is then scaled relatively to that side. So that species with the same abundance are plotted with boxes of the same size.

Author(s)

Tobias Bauer tobias.bauer-2@uni-hamburg.de

See Also

For a different plot of food webs see visweb

Examples

data(Safariland)
plotweb(Safariland)

# To let the plot look a bit more modern
plotweb(Safariland, horizontal = TRUE, curved_links = TRUE)

bipartite documentation built on Sept. 9, 2025, 5:58 p.m.