Manipulates gexf objects adding and removing nodes and edges from
both, its dataframe representation and its XML representation.
Usage
add.gexf.node(
graph,
id = NA,
label = NA,
start = NULL,
end = NULL,
vizAtt = list(color = NULL, position = NULL, size = NULL, shape = NULL, image = NULL),
atts = NULL
)
add.gexf.edge(
graph,
source,
target,
id = NULL,
type = NULL,
label = NULL,
start = NULL,
end = NULL,
weight = 1,
vizAtt = list(color = NULL, thickness = NULL, shape = NULL),
atts = NULL,
digits = getOption("digits")
)
rm.gexf.node(graph, id = NULL, number = NULL, rm.edges = TRUE)
rm.gexf.edge(graph, id = NULL, number = NULL)
add.node.spell(
graph,
id = NULL,
number = NULL,
start = NULL,
end = NULL,
digits = getOption("digits")
)
add.edge.spell(
graph,
id = NULL,
number = NULL,
start = NULL,
end = NULL,
digits = getOption("digits")
)Arguments
- graph
A gexf-class object.
- id
A node/edge id (normally numeric value).
- label
A node/edge label.
- start
Starting time period
- end
Ending time period
- vizAtt
A list of node/edge viz attributes (see
write.gexf()).- atts
List of attributes, currently ignored.
- source
Source node's id.
- target
Target node's id.
- type
Type of connection (edge).
- weight
Edge weight.
- digits
Integer. Number of decimals to keep for nodes/edges sizes. See
print.default()- number
Index number(s) of a single or a group of nodes or edges.
- rm.edges
Whether to remove or not existing edges.
Value
A gexf object (see write.gexf()).
Details
new.gexf.graph Creates a new gexf empty object (0 nodes 0
edges).
add.gexf.node and add.gexf.edge allow adding nodes and edges
to a gexf object (graph) one at a time. rm.gexf.node and
rm.gexf.edges remove nodes and edges respectively.
In the case of rm.gexf.node, by default every edge linked to the node
that is been removed will also be removed (rm.edges = TRUE).
Spells
While the start and end attributes can be included in nodes and edges,
spells provide a way to represent presence and absence of elements throughout
time.
We can use spells to indicate windows during which the element is present or not. For example, a node that shows up from time 1 to time two and re-appears after time four can have two spells:
In the case of the functions add.edge.spell and add.node.spell, edges and
nodes to which you want to add spells should already exist.
Examples
if (interactive()) {
demo(gexfbuildfromscratch)
}
# Creating spells ------------------------------------------------------
g <- new.gexf.graph()
# Adding a few nodes + edges
g <- add.gexf.node(g, id = 0, label = "A")
g <- add.gexf.node(g, id = 1, label = "B")
g <- add.gexf.node(g, id = 2, label = "C")
g <- add.gexf.edge(g, source = 0, target = 1)
g <- add.gexf.edge(g, source = 0, target = 2)
# Now we add spells:
# - Node 0: 1.0 -> 2.0, 3.0 -> Inf
# - edge 1: 1.0 -> 2.0, 3.5 -> Inf
g <- add.node.spell(g, 0, start = 1, end = 2)
g <- add.node.spell(g, 0, start = 3)
g <- add.edge.spell(g, 1, start = 1, end = 2)
g <- add.edge.spell(g, 1, start = 3.5)
g
#> <?xml version="1.0"?>
#> <gexf schemaLocation="http://www.gexf.net/1.2draft http://www.gexf.net/1.2draft/gexf.xsd" version="1.2" xmlns="http://www.gexf.net/1.2draft" xmlns:viz="http://www.gexf.net/1.1draft/viz" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
#> <meta lastmodifieddate="2026-08-06">
#> <creator>NodosChile</creator>
#> <description>A graph file writing in R using 'rgexf'</description>
#> <keywords>gexf graph, NodosChile, R, rgexf</keywords>
#> </meta>
#> <graph mode="static">
#> <nodes>
#> <node id="0" label="A">
#> <spells>
#> <spell start="1" end="2"/>
#> <spell start="3"/>
#> </spells>
#> </node>
#> <node id="1" label="B"/>
#> <node id="2" label="C"/>
#> ...
#> </nodes>
#> <edges>
#> <edge id="1" source="0" target="1" weight="1">
#> <spells>
#> <spell start="1" end="2"/>
#> <spell start="3.5"/>
#> </spells>
#> </edge>
#> <edge id="2" source="0" target="2" weight="1"/>
#> </edges>
#> </graph>
#> </gexf>