Description Usage Arguments Details Value Functions Author(s) References See Also Examples
A set of primitive functions for creating and munipulating graphs.
1 2 3 4 5 6 7 8 9 10 11 12 13 | 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)
|
n |
The number of vertex 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 edge to be added (vertex labels or indices). |
to |
The destinations of the edge 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
|
A new graph can be populated with n
vertices using function
pop.graph
and 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 graph functions to convert a
rooted phylogenetic tree of class ‘phylo’ (see
ape-package
) to a graph-class
object. It recycles
tip labels and 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.
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.
pop.graph
: Creates a graph and populates it with vertices.
add.vertex
: Adds vertices to an existing graph.
add.edge
: Adds edges to a graph.
rm.edge
: Removes edges from a graph.
rm.vertex
: Removes vertices from a graph.
collapse.vertex
: Removes vertices from a graph while also removing their associated edges.
Phylo2DirectedGraph
: Transforms a phylogenetic tree into a directed graph.
Guillaume Guenard, with contribution from Pierre Legendre Maintainer: Guillaume Guenard <guillaume.guenard@gmail.com>
Guénard, G., Legendre, P., and Peres-Neto, P. 2013. Phylogenetic eigenvector maps (PEM): a framework to model and predict species traits. Meth. Ecol. Evol. 4: 1120–1131
Makarenkov, V., Legendre, L. & Desdevise, Y. 2004. Modelling phylogenetic relationships using reticulated networks. Zool. Scr. 33: 89–96
Blanchet, F. G., Legendre, P. & Borcard, D. 2008. Modelling directional spatial processes in ecological data. Ecol. Model. 215: 325–336
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | ## 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)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.