graph-functions {MPSEM} | R Documentation |
MPSEM graph Manipulation Functions
Description
A set of primitive functions for creating and munipulating MPSEM graphs.
Usage
pop.graph(n, vertex = list(), label = NULL)
add.vertex(x, n, vertex = list(), label = NULL)
add.edge(x, from, to, edge = list(), label = NULL)
rm.edge(x, id)
rm.vertex(x, id)
collapse.vertex(x, id)
Phylo2DirectedGraph(tp)
Arguments
n |
The number of vertices to populate a new graph ( |
vertex |
A list of vertex properties. |
label |
Labels to be given to edges or vertices. |
x |
A |
from |
The origins of the edges to be added (vertex labels or indices). |
to |
The destinations of the edges to be added (vertex labels or indices). |
edge |
A list of edge properties. |
id |
Indentity (label or index) of vertex or edge to be removed. |
tp |
Phylogenetic tree object of class ‘phylo’, as defined in
|
Details
A new graph can be populated with n
vertices using function
pop.graph
. Additional vertices can be added later with function
add.vertex
. The graphs so created contain no edges; the latter are
added using function add.edge
. Vertices and edges are removed using
functions rm.vertex
and rm.edge
, respectively.
Function collapse.vertex
allows one to remove a vertex while
reestablishing the connections between the vertices located above and below
that vertex using a new set of edges.
Function Phylo2DirectedGraph
uses the MPSEM graph functions to convert
a rooted phylogenetic tree of class ‘phylo’ (see
ape-package
) to a graph-class
object. It
recycles tip labels. It also creates default node labels if they were absent
from the ‘phylo’ object, and uses them as vertex labels. The resulting
acyclic graph can then be edited to represent cases that do not have a tree
topology.
Value
The function returns a graph-class
object. Objects
returned by Phylo2DirectedGraph
have a numeric
edge property called ‘distance’ featuring branch lengths, and a
link{logical}
vertex property called ‘species’ specifying
whether a vertex is a tree tip or an internal node.
Functions
-
pop.graph()
: Create GraphCreate a graph and populates it with vertices.
-
add.vertex()
: Add VerticesAdd vertices to an existing graph.
-
add.edge()
: Add EdgesAdd edges to a graph.
-
rm.edge()
: Remove EdgesRemove edges from a graph.
-
rm.vertex()
: Remove VerticesRemove vertices from a graph.
-
collapse.vertex()
: Collapse VerticesRemove vertices from a graph: remove vertices together with their associated edges.
-
Phylo2DirectedGraph()
: Phylogenetic Tree ConversionCreate a new
graph-class
object from a phylo-class object (phylogenetic tree).
Author(s)
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>
References
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
See Also
Examples
## Populate a graph with 7 vertices labeled A-G having properties x and y:
gr <- pop.graph(n=7,
vertex=list(x=rnorm(7,0,1),y=rnorm(7,0,1)),
label=c("A","B","C","D","E","F","G"))
gr
## Adding 3 vertices H, I, and J with property x (y is absent) and a new
## property z (type character), which is unknown for A-G:
gr <- add.vertex(x=gr,
n=3,
label=c("H","I","J"),
vertex=list(x=rnorm(3,0,1),z=c("A","B","C")))
gr
gr$vertex
## Adding 10 edges, labeled E1-E10 and with properties a and b, to the graph:
gr <- add.edge(x=gr,
from=c("A","B","B","C","C","D","D","E","E","F"),
to=c("A","C","D","E","F","F","G","H","I","J"),
edge=list(a=rnorm(10,0,1),b=rnorm(10,0,1)),
label=paste("E",1:10,sep=""))
gr
gr$edge
## Removing edges 2, 4, and 7 from the graph:
print(rm.edge(gr,id=c(2,4,7)))
## Removing vertices 1, 3, 7, and 10 from the graph:
print(rm.vertex(gr,id=c(1,3,7,10)))
# Notice that the edges that had one of the removed vertex as their
# origin or destination are also removed:
print.default(rm.vertex(gr,id=c(1,3,7,10)))
## Vertex collapsing.
x <- pop.graph(n=9,label=c("A","B","C","D","E","F","G","H","I"))
x <- add.edge(x,from=c("A","A","B","B","C","C","D","D","E","E"),
to=c("B","C","D","E","E","I","F","G","G","H"),
label=paste("E",1:10,sep=""),
edge=list(length=c(1,2,3,2,1,3,2,2,1,3)))
print.default(x)
for(i in c("A","B","C","D","E","F","G","H","I"))
print(collapse.vertex(x,id=i))
if(require(ape)) {
tree1 <- read.tree(
text=paste(
"(((A:0.15,B:0.2)N4:0.15,C:0.35)N2:0.25,((D:0.25,E:0.1)N5:0.3,",
"(F:0.15,G:0.2)N6:0.3)N3:0.1)N1;",sep=""))
x <- Phylo2DirectedGraph(tree1)
print(x)
}