create_monolayer_network: Creates a monolayer network object.

View source: R/create_monolayer_network.R

create_monolayer_networkR Documentation

Creates a monolayer network object.

Description

Automatically identifies if the input is a matrix or an edge list and creates a monolayer object.

Usage

create_monolayer_network(
  x,
  directed = NULL,
  bipartite = NULL,
  group_names = c("set_cols", "set_rows"),
  node_metadata = NULL
)

Arguments

x

input data in the format of a matrix, edge list or an igraph object.

directed

Is the network directed?

bipartite

Is the network bipartite? Ignored when the input is an igraph object.

group_names

For bipartite networks: name of the groups in the columns and rows, respectively (e.g., parasites and hosts).

node_metadata

Following the igraph method of graph_from_data_frame. First column must be have names matching those in x.

Details

Converts between edge list and matrix formats and creates a monolayer object. It a wrapper function for list_to_matrix, matrix_to_list_unipartite, matrix_to_list_bipartite. Node metadata can only be included with an edge list input.

Value

A monolayer object.

See Also

list_to_matrix, matrix_to_list_unipartite, monolayer.

Examples

library(igraph)

# A bipartite network from package bipartte
x <- create_monolayer_network(bipartite::memmott1999, bipartite = TRUE,
directed = FALSE, group_names = c('Animals','Plants'))

# A bipartite network as an igraph object

# Generate a random bipartite network in igraph
g <- igraph::sample_bipartite(10,16,p=0.3, type = 'gnp', directed = TRUE, mode = 'in')
V(g)$name <- letters # name the nodes
V(g)$gender <- sample(c('F','M'), size = 26, replace = TRUE) # Add a node attribute
E(g)$weight=runif(ecount(g)) # Add edge weights
plot(g, layout=layout.bipartite)
create_monolayer_network(g, group_names = c('Parasites','Hosts'))





emln documentation built on May 6, 2026, 1:06 a.m.