Title: | Tools to Analyse and Visualise Bipartite Networks |
---|---|
Description: | Tools to analyse and visualise bipartite networks. |
Authors: | Francisco Rodriguez-Sanchez [aut, cre] |
Maintainer: | Francisco Rodriguez-Sanchez <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.0.5 |
Built: | 2024-11-13 04:59:23 UTC |
Source: | https://github.com/Pakillo/network.tools |
Remove columns from an interaction matrix where all values are zero.
drop_empty_cols(mat = NULL, na.rm = TRUE)
drop_empty_cols(mat = NULL, na.rm = TRUE)
mat |
A matrix containing interaction data. |
na.rm |
Logical. If TRUE, NA values will be ignored for deciding if a column should be removed. If FALSE, columns having NA values will never be removed. |
A matrix
mat <- matrix(c(0,0,0, 1,1,0, 0,0,NA), ncol = 3, byrow = TRUE) mat drop_empty_cols(mat) drop_empty_cols(mat, na.rm = FALSE)
mat <- matrix(c(0,0,0, 1,1,0, 0,0,NA), ncol = 3, byrow = TRUE) mat drop_empty_cols(mat) drop_empty_cols(mat, na.rm = FALSE)
Remove rows from an interaction matrix where all values are zero.
drop_empty_rows(mat = NULL, na.rm = TRUE)
drop_empty_rows(mat = NULL, na.rm = TRUE)
mat |
A matrix containing interaction data. |
na.rm |
Logical. If TRUE, NA values will be ignored for deciding if a row should be removed. If FALSE, rows having NA values will never be removed. |
A matrix
mat <- matrix(c(0,0,0, 1,1,0, 0,0,NA), ncol = 3, byrow = TRUE) mat drop_empty_rows(mat) drop_empty_rows(mat, na.rm = FALSE)
mat <- matrix(c(0,0,0, 1,1,0, 0,0,NA), ncol = 3, byrow = TRUE) mat drop_empty_rows(mat) drop_empty_rows(mat, na.rm = FALSE)
Expand interaction dataset to include zeroes (unobserved interactions)
expand_unobs( df = NULL, plant.var = "Plant", animal.var = "Animal", int.var = "Visits", fill.value = 0 )
expand_unobs( df = NULL, plant.var = "Plant", animal.var = "Animal", int.var = "Visits", fill.value = 0 )
df |
A data frame with interaction presence or frequency data |
plant.var |
character. Name of the column representing plants. |
animal.var |
character. Name of the column representing animals. |
int.var |
character. Name of the column representing interaction presence or frequency. |
fill.value |
Value to use in |
A data frame
data(web) df <- web[sample(1:nrow(web), size = 30), ] df.expand <- expand_unobs(df)
data(web) df <- web[sample(1:nrow(web), size = 30), ] df.expand <- expand_unobs(df)
Calculate indices of niche width and individual specialisation, following Bolnick et al. 2002 (doi:10.1890/0012-9658(2002)083[2936:MILRS]2.0.CO;2).
TNW
calculates the Total Niche Width of the population, using Shannon diversity.
WIC
calculates the Within-Individual Component of niche width
as a weighted average of individuals' Shannon diversity
(i.e. the Shannon diversity value of each individual plant is weighted by
the proportion of visits or interactions received by that plant).
WIC
can also return the individual Shannon diversity values, if indiv = TRUE
.
indiv_spec
returns a data.frame with the following columns:
WIC (Within-Individual Component)
TNW (Total Niche Width)
IndSpec (Individual Specialisation index, calculated as the ratio WIC / TNW).
indiv_spec(net) TNW(net) WIC(net, indiv = FALSE)
indiv_spec(net) TNW(net) WIC(net, indiv = FALSE)
net |
A matrix or data.frame containing interaction data. Plants in rows, Animals in columns. Numbers need not be integers (i.e. counts), can be relative abundances or interaction frequencies. |
indiv |
Logical. If TRUE, return individual Shannon diversity values. If FALSE, return the weighted average of individual Shannon diversity, weighted by the proportion of interactions represented by each plant (i.e. the WIC). |
A numeric value or vector for WIC
and TNW
,
a data.frame in the case of indiv_spec
Ideally net
should not contain missing data (NA). If present, they will
be ignored.
Bolnick DI, LH Yang, JA Fordyce, JM Davis, and Svanback R. 2002. Measuring individual-level resource specialization. Ecology 83: 2936-2941.
data(web) net <- long2wide(web) indiv_spec(net) WIC(net) WIC(net, indiv = TRUE) TNW(net)
data(web) net <- long2wide(web) indiv_spec(net) WIC(net) WIC(net, indiv = TRUE) TNW(net)
Transform interaction data from long to wide format
long2wide( df = NULL, plant.var = "Plant", animal.var = "Animal", int.var = "Visits", exclude.noint = TRUE, fill.value = NA, sort = TRUE )
long2wide( df = NULL, plant.var = "Plant", animal.var = "Animal", int.var = "Visits", exclude.noint = TRUE, fill.value = NA, sort = TRUE )
df |
A data frame with interaction presence or frequency data |
plant.var |
character. Name of the column representing plants. |
animal.var |
character. Name of the column representing animals. |
int.var |
character. Name of the column representing interaction presence or frequency. |
exclude.noint |
Logical. Exclude plants/animals with no interactions? Default is TRUE. |
fill.value |
Value to fill empty cells in the matrix. Default is NA. |
sort |
Sort matrix rows and columns by frequency? |
A matrix with plants and animals as row and column names, respectively.
data(web) long2wide(web)
data(web) long2wide(web)
Plot bipartite interaction web as a heatmap
plot_web_heatmap( df, plant.var = "Plant", animal.var = "Animal", int.var = "Visits", binarize = FALSE, sort = TRUE, zero.na = TRUE, na.colour = "white" )
plot_web_heatmap( df, plant.var = "Plant", animal.var = "Animal", int.var = "Visits", binarize = FALSE, sort = TRUE, zero.na = TRUE, na.colour = "white" )
df |
A data frame with interaction presence or frequency data |
plant.var |
character. Name of the column representing plants. |
animal.var |
character. Name of the column representing animals. |
int.var |
character. Name of the column representing interaction presence or frequency. |
binarize |
Logical. Discretize int.var into two categories? (Default is FALSE). |
sort |
Logical. If TRUE, sort rows and columns by prevalence to show nestedness. |
zero.na |
Logical. Show zeros as NA? |
na.colour |
Colour to be used for NA. |
A ggplot object.
data(web) plot_web_heatmap(web) plot_web_heatmap(web, zero.na = FALSE) plot_web_heatmap(web, sort = FALSE) plot_web_heatmap(web, binarize = TRUE)
data(web) plot_web_heatmap(web) plot_web_heatmap(web, zero.na = FALSE) plot_web_heatmap(web, sort = FALSE) plot_web_heatmap(web, binarize = TRUE)
Example data frame containing data for a bipartite web of number of visits from 8 animals to 4 plants.
web
web
web
A data frame with 32 rows and 3 columns:
Plant ID
Animal ID
Number of visits
dataset simulated
Transform interaction data from wide to long format
wide2long(mat = NULL, int.name = "Visits")
wide2long(mat = NULL, int.name = "Visits")
mat |
A matrix containing interaction data. Plants in rows, Animals in columns. |
int.name |
character. Column name for the interaction values. |
A data frame with three columns: "Plant", "Animal", and interaction values.
data(web) mat <- long2wide(web) mat df <- wide2long(mat) df
data(web) mat <- long2wide(web) mat df <- wide2long(mat) df