#' Make network
#' @description Make network for a competitive network from nodes and edges
#' @name network_make
#' @param nodes node list
#' @param edges edge list
#' @return an `igraph` object
network_make <- function(nodes, edges) {
# Nodes and edges
nodes <- filter(nodes)
edges <- filter(edges) %>% dplyr::select(from, to, interaction)
# Make undirected edges for coexistence pairs
edges_coext <- filter(edges, interaction == "coexistence")
edges_coext[, c("from", "to")] <- edges_coext[, c("to", "from")]
edges <- rbind(edges, edges_coext) # Edges for coexistence links
# Make undirected edges for non-growth pairs
edges_nongrowth <- filter(edges, interaction == "non-growth")
edges_nongrowth[, c("from", "to")] <- edges_nongrowth[, c("to", "from")]
edges <- rbind(edges, edges_nongrowth) # Edges for coexistence links
# Make graph
net <- graph_from_data_frame(d = edges, vertices = nodes, directed = T)
# Edges attributes
edge_colrs <- c("blue", "red", "grey90")
E(net)$arrow.size <- .2
E(net)$edge.color[E(net)$interaction == "exclusion"] <- 1
E(net)$edge.color[E(net)$interaction == "coexistence"] <- 2
E(net)$edge.color[E(net)$interaction == "non-growth"] <- 3
return(net)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.