| graph-functions | R Documentation |
A set of primitive functions for creating and munipulating MPSEM graphs.
graph(data = data.frame())
add.vertex(x, data = data.frame())
add.edge(x, from, to, data = data.frame())
rm.edge(x, id)
rm.vertex(x, id)
data |
A |
x |
A |
from |
An integer or character vector. References to the origin of the edges to be added. |
to |
An integer or character vector. The destinations of the edges to be added (vertex references). |
id |
An integer or character vector. The identity of vertex or edge to be removed (references). |
A new graph is populated with vertices using function
graph(). The function must be provided with a data frame. This data
frame may be a 0 column data frame as long as its row.names attribute
contains the number of elements necessary to reference the vertices.
Additional vertices can be added later with function add.vertex(). The
graph thus created contains no edge; the latter are added using function
add.edge(). Edges and vertices are removed using functions
rm.edge() and rm.vertex(), respectively.
graph(): Create Graph
Create a graph and populates it with vertices.
add.vertex(): Add Vertices
Add vertices to an existing graph.
add.edge(): Add Edges
Add edges to a graph.
rm.edge(): Remove Edges
Remove edges from a graph.
rm.vertex(): Remove Vertices
Remove vertices from a graph.
Guillaume Guénard [aut, cre] (<https://orcid.org/0000-0003-0761-3072>), Pierre Legendre [ctb] (<https://orcid.org/0000-0002-3838-3305>) Maintainer: Guillaume Guénard <guillaume.guenard@umontreal.ca>
Guénard, G., Legendre, P., and Peres-Neto, P. 2013. Phylogenetic eigenvector maps: a framework to model and predict species traits. Methods in Ecology and Evolution 4: 1120-1131
Makarenkov, V., Legendre, L. & Desdevise, Y. 2004. Modelling phylogenetic relationships using reticulated networks. Zoologica Scripta 33: 89-96
Blanchet, F. G., Legendre, P. & Borcard, D. 2008. Modelling directional spatial processes in ecological data. Ecological Modelling 215: 325-336
## Populate a graph with 7 vertices labeled A-G and edge properties x and y:
data.frame(
quantitative = c(1.1,7.2,7.2,4.1,5.5,6.9,3.3),
factor = factor(c("A","A","A","B","B","B","B")),
row.names = c("A","B","C","D","E","F","G")
) %>%
graph -> x
## Note from package magrittr:
## x %>% f(y, z) is equivalent to f(x, y, z)
## x %<>% f(y, z) is equivalent to x <- f(x, y, z)
## Add three vertices without descriptors:
x %>% add.vertex(
data = data.frame(row.names = c("H","I","J"))
)
## This is another way to add vertices:
x %<>% add.vertex(
data = data.frame(
factor = factor(c("C","C","C")),
ordered = ordered(c(1,2,2)),
row.names = c("H","I","J")
)
)
## Adding 10 edges, labeled E1-E10 and with properties d and r, to the graph:
x %<>% add.edge(
from = c("A","B","B","C","C","D","D","E","E","F"),
to = c("A","C","D","E","F","F","G","H","I","J"),
data = data.frame(
distance = c(1,5,2,3,3,2,5,1,1,1),
reversible = c(TRUE,FALSE,FALSE,FALSE,TRUE,TRUE,FALSE,FALSE,TRUE,FALSE),
row.names = paste("E",1:10,sep="")
)
)
## Adding three more edges, this time without variable 'reversible', but
## adding a variable called 'factor':
x %<>% add.edge(
from = c("E","F","G"),
to = c("A","B","C"),
data.frame(
distance = c(2,3,1),
factor = factor(c("S","S","G")),
row.names = c("E1","E11","E23")
)
)
## Removing two edges (E3 and E5):
x %<>% rm.edge(id=c("E3","E5"))
## Removing vertices B, F, and G with their associated edges:
x %<>% rm.vertex(id=c("B","F","G"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.