| Title: | Plots for Bipartite Networks in R |
| Version: | 0.1.3 |
| Description: | Provides functions to plot bipartite ecological networks using 'ggplot2' graphics, including interaction webs, node-link layouts, and matrix representations. Species interaction data in the form of adjacency matrices, or 'network' and 'igraph' graph objects, can be plotted directly. |
| Depends: | R (≥ 3.1), ggplot2 (≥ 2.0.0) |
| License: | GPL-3 |
| Imports: | network, igraph, GGally |
| Suggests: | knitr, rmarkdown, bipartite, testthat (≥ 3.0.0) |
| VignetteBuilder: | knitr |
| URL: | http://pjordanolab.ebd.csic.es/resources/ |
| BugReports: | https://github.com/pedroj/bipartite_plots/issues |
| Encoding: | UTF-8 |
| Config/roxygen2/version: | 8.1.0 |
| Config/testthat/edition: | 3 |
| NeedsCompilation: | no |
| Packaged: | 2026-09-09 15:27:03 UTC; pedro |
| Author: | Pedro Jordano [aut, cre] |
| Maintainer: | Pedro Jordano <jordano@ebd.csic.es> |
| Repository: | CRAN |
| Date/Publication: | 2026-09-17 13:20:15 UTC |
A package to plot bipartite interaction networks in R.
Description
Bipartite networks
Details
The ggbipart package includes a series of R functions aimed to plot bipartite networks within the ggplot2 environment. The library relies heavily on code developed by Francois Briatte for the ggnet library. Bipartite networks are a special type of network where nodes are of two distinct types or sets, so that connections (links) only exist among nodes of the different sets. As in other types of network, bipartite structures can be binary (only the presence/absence of the links is mapped) or quantitative (weighted), where the links can have variable importance or weight. To plot, we start with an adjacency or incidence matrix. Using matrices that illustrate ecological interactions among species, such as the mutualisttic interactions of animal pollinators and plant flowers. The two sets (modes) of these bipartite networks are animals (e.g., pollinators) and plants species. From any adjacency matrix we can get a network object or an igraph object for plotting and analysis.
Installation.
'# devtools::install_github("pedroj/bipartite_plots")'
'# library(ggbipart)'
Suggested references:
Pocock, M.J.O., Evans, D.M., Fontaine, C., Harvey, M., Julliard, R., McLaughlin, O., Silvertown, J., Tamaddoni-Nezhad, A., White, P.C.L. and Bohan, D.A. (2016) The visualisation of ecological networks, and their use as a tool for engagement, advocacy and management. Advances in Ecological Research, 1st ed, pp. 41-85. Elsevier Ltd.
Bascompte, J., Jordano, P. (2014) Mutualistic Networks. Princeton University Press, Princeton, NJ.
Author(s)
Pedro Jordano
See Also
Useful links:
Report bugs at https://github.com/pedroj/bipartite_plots/issues
Function bip_binplot, to plot a network object corresponding to a binary adjacency matrix.
Description
mymat is the adjacency matrix, to get the dimensions from. net is a network object corresponding to mymat. The object net can be initialized with function bip_netinit.R
Usage
bip_binplot(
mymat,
net,
usearrows = FALSE,
mode = "kamadakawai",
displaylabels = TRUE,
label.cex = 0.6,
vertex.cex = 1,
edge.lty = 0.7
)
Arguments
mymat |
the adjacency matrix. Input can be a data.frame or a matrix, representing the adjacency matrix. |
net |
a network object. |
usearrows |
a ntework object. |
mode |
mde of the network object. |
displaylabels |
whether or not display the node labels. |
label.cex |
size of label fonts. |
vertex.cex |
size of nodes. |
edge.lty |
line type for the edges. |
Details
Plot of a network object corresponding to a binary adjacency matrix (qualitative, presence-absence, data.
Value
A plot object.
Examples
mat <- as.matrix(read.csv(
system.file("extdata", "sdw02_adj_fru.csv", package = "ggbipart"),
comment.char = "#", row.names = 1, check.names = FALSE))
net <- bip_init_network(mat)
bip_binplot(mat, net)
Function to compute scaled edge weights for plotting.
Description
Function to compute scaled edge weights for plotting.
Usage
bip_edgewt(M, x = 30)
Arguments
M |
the adjacency matrix. Input can be a data.frame or a matrix, representing the adjacency matrix. |
x |
a scaling parameter. Just tune it (x parameter) to adequate values for the specific dataset. |
Value
A vector of scaled edge weights for plotting.
Examples
mat <- as.matrix(read.csv(
system.file("extdata", "sdw02_adj_fru.csv", package = "ggbipart"),
comment.char = "#", row.names = 1, check.names = FALSE))
# One scaled weight per non-zero interaction; the largest equals x.
wt <- bip_edgewt(mat, x = 30)
summary(wt)
Plotting bipartite networks from adjacency matrix of a two-mode network.
Description
Plotting bipartite networks from adjacency matrix of a two-mode network.
Usage
bip_ggnet(
net,
mat,
mode = "fruchtermanreingold",
size = 9,
palette = c(A = "grey", P = "gold"),
color = "mode",
label.size = 3,
label = FALSE,
shape = "mode",
edge.label = NULL,
layout.exp = 0,
mode1 = "P",
mode2 = "A"
)
Arguments
net |
the network object. Either a two-mode object of class
|
mat |
the adjacency matrix. Input can be a data.frame or a matrix, representing the adjacency matrix.
Optional: if not supplied it is extracted from |
mode |
the type of energy-minimization algorithm to plot the network. By default it's mode= "fruchtermanreingold". |
size |
Specify size for nodes. |
palette |
Define the color palette to use. |
color |
Node color. |
label.size |
Size for node text labels. |
label |
Whether or not add node labels. |
shape |
Geometric shape to be used for nodes. |
edge.label |
Whether or not add edge labels. |
layout.exp |
Layout information. |
mode1 |
name for the upper mode (matrix rows), used when |
mode2 |
name for the lower mode (matrix columns), used when |
Details
Inputs are a net object and its corresponding adjacency matrix. It uses the adjacency matrix to compute scaled weighted edges with function edgewt. Part of the code from Francois Briatte, using package ggnet. DATE: 15Jul2013. Updated to ggnet 11/11/2016. ggnet2 automatically detects two-mode graphs from their bipartite network attribute. To simplify the plotting of each mode, it understands arguments of the form [alpha, color, shape, size] = "mode", which will mark the primary mode as "actor" and the secondary mode as "event". #—————————————————————————- Detect and color the mode To use the mode of the nodes as the basis for their colors, all the user has to do is to pass the color = "mode" argument, and then to style the "actor" and "event" values. #—————————————————————————
Value
A ggplot object.
Examples
mat <- as.matrix(read.csv(
system.file("extdata", "sdw02_adj_fru.csv", package = "ggbipart"),
comment.char = "#", row.names = 1, check.names = FALSE))
net <- bip_init_network(mat)
bip_ggnet(net, mat)
# igraph input works too, and the matrix can be omitted
g <- bip_init_igraph(mat)
bip_ggnet(g)
Plotting bipartite networks from adjacency matrix of a two-mode network.
Description
Plotting bipartite networks from adjacency matrix of a two-mode network.
Usage
bip_igplot(mymat, g)
Arguments
mymat |
the adjacency matrix. Input can be a data.frame or a matrix, representing the adjacency matrix. |
g |
the graph object |
Details
Plotting bipartite networks from adjacency weighted matrix of two-mode network. A modified version of the plotting, with package igraph. Requires input of the weighted "mymmat" matrix and its graph object, "g". #—————————————————————————
Value
An igraph graph object.
Examples
mat <- as.matrix(read.csv(
system.file("extdata", "sdw02_adj_fru.csv", package = "ggbipart"),
comment.char = "#", row.names = 1, check.names = FALSE))
g <- bip_init_igraph(mat)
bip_igplot(mat, g)
Function to initialize a bipartite web for library igraph (type igraph).
Description
Function to initialize a bipartite web for library igraph (type igraph).
Usage
bip_init_igraph(mat)
Arguments
mat |
the adjacency matrix. Input can be a data.frame or a matrix, representing the adjacency matrix. |
Details
Function to initialize a bipartite web for library igraph (type igraph), starting from a weighted adjacency matrix. Create the graph object (a bipartite, weighted graph) for igraph.
Value
A graph object.
Examples
mat <- as.matrix(read.csv(
system.file("extdata", "sdw02_adj_fru.csv", package = "ggbipart"),
comment.char = "#", row.names = 1, check.names = FALSE))
g <- bip_init_igraph(mat)
g
Function to initialize a bipartite web for library network (type network).
Description
Function to initialize a bipartite web for library network (type network).
Usage
bip_init_network(mymat, mode1 = "P", mode2 = "A")
Arguments
mymat |
the adjacency matrix. Input can be a data.frame or a matrix, representing the adjacency matrix. |
mode1 |
name for the upper mode. |
mode2 |
name for the lower mode. |
Details
Function to initialize a bipartite web for library network (type network),
Value
A network object.
Examples
mat <- as.matrix(read.csv(
system.file("extdata", "sdw02_adj_fru.csv", package = "ggbipart"),
comment.char = "#", row.names = 1, check.names = FALSE))
net <- bip_init_network(mat)
net
Function to plot a bipartite weighted network.
Description
Function to plot a bipartite weighted network.
Usage
bip_qtplot(mat)
Arguments
mat |
the adjacency matrix. Input can be a data.frame or a matrix, representing the adjacency matrix. |
Details
Plotting a bipartite network from the weighted (quantitative) adjacency matrix of a two-mode network. Uses objects of type network and a traditional plot.
Value
A plot object.
Examples
mat <- as.matrix(read.csv(
system.file("extdata", "sdw02_adj_fru.csv", package = "ggbipart"),
comment.char = "#", row.names = 1, check.names = FALSE))
bip_qtplot(mat)
Function to plot layout coordinates for railway network plot.
Description
Function to plot layout coordinates for railway network plot.
Usage
bip_railway(mymat, nodesize = 9, label = FALSE)
Arguments
mymat |
a matrix whose rows contain the x,y coordinates of the vertices of d. |
nodesize |
size of nodes. |
label |
should nodes be labelled? |
Details
Plotting a bipartite network from the weighted (quantitative) adjacency matrix of a two-mode network.
# Code for separately nudging and rotating labels of modes. geom_text(aes(label= network.vertex.names(test.net)), angle<- ifelse(network.vertex.names(test.net)[1:dim(mymat)[1]], 0, 45), nudge_x<- ifelse(network.vertex.names(test.net)[1:dim(mymat)[1]], 0.5, -0.5))
Value
A plot object.
Examples
mat <- as.matrix(read.csv(
system.file("extdata", "sdw02_adj_fru.csv", package = "ggbipart"),
comment.char = "#", row.names = 1, check.names = FALSE))
bip_railway(mat, label = TRUE)
Function to vectorze an adjacency matrix.
Description
Function to vectorze an adjacency matrix.
Usage
vectorize(mat)
Arguments
mat |
the adjacency matrix. |
Details
Like in STACK: Turn table (C) into (D): The input matrix should be read with row.names=1 option and a blank entry at the upper left corner.
C a b c d A 3 2 . . B . . 1 1
D A a 3 A b 2 A c . A d . B a . B b . B c 1 B d 1 #————————————————————-
Value
A vector object.
Examples
# A weighted plant-frugivore adjacency matrix shipped with the package.
mat <- as.matrix(read.csv(
system.file("extdata", "sdw02_adj_fru.csv", package = "ggbipart"),
comment.char = "#", row.names = 1, check.names = FALSE))
edges <- vectorize(mat)
head(edges)