write.graph {igraph} | R Documentation |
write.graph
is a general function for exporting
graphs to foreign file formats, however not many formats are
implemented right now.
write.graph(graph, file, format=c("edgelist", "pajek", "ncol", "lgl", "graphml", "dimacs", "gml", "dot"), ...)
graph |
The graph to export. |
file |
A connection or a string giving the file name to write the graph to. |
format |
Character string giving the file format. Right now
pajek , graphml , dot ,
gml , edgelist , lgl ,
ncol and dimacs are implemented. As of igraph 0.4 this
argument is case insensitive.
|
... |
Other, format specific arguments, see below. |
The edgelist
format is a simple text file, with one edge in a
line, the two vertex ids separated by a space character. The file is
sorted by the first and the second column. This format has no
additional arguments.
The Pajek format is a text file, see read.graph
for
details. Appropriate vertex and edge attributes are also written to
the file. This format has no additional arguments.
The GraphML format is a flexible XML based format. See
read.graph
for GraphML details. Vertex and edge
attributes are also written to the file. This format has no additional
arguments.
The dot format is used by the popular GraphViz program. Vertex and edge attributes are written to the file. There are no additional arguments for this format.
The lgl
format is also a simple text file, this is the
format expected by the 'Large Graph Layout' layout generator software.
See read.graph for details.
Additional arguments:
NULL
if you want to use numeric
vertex ids even if there is a ‘name’ vertex attribute.NULL
here if you want to omit the weights.TRUE
the isolate vertices are
also written to the file, they are omitted by default.
The ncol
format is also used by LGL, it is a text file, see
read.graph for details.
Additional arguments:
NULL
if you want to use numeric
vertex ids even if there is a ‘name’ vertex attribute.NULL
here if you want to omit the weights.
The dimacs
file format, more specifically the
version for network flow problems, see the files at
ftp://dimacs.rutgers.edu/pub/netflow/general-info/
This is a line-oriented text file (ASCII) format. The first
character of each line defines the type of the line. If the first
character is c
the line is a comment line and it is
ignored. There is one problem line (p
in the file, it
must appear before any node and arc descriptor lines. The problem
line has three fields separated by spaces: the problem type
(min
, max
or asn
), the
number of vertices and number of edges in the graph.
Exactly two node identification lines are expected
(n
), one for the source, one for the target vertex.
These have two fields: the id of the vertex and the type of the
vertex, either s
(=source) or t
(=target). Arc lines start with a
and have three
fields: the source vertex, the target vertex and the edge capacity.
Vertex ids are numbered from 1.
Additional arguments:
NULL
(the
default) then it is taken from the source
graph attribute.NULL
(the
default) then it is taken from the target
graph attribute.NULL
(the default) then it is taken from the
capacity
edge attribute.GML is a quite general textual format, see http://www.infosun.fim.uni-passau.de/Graphlet/GML/ for details.
The graph, vertex and edges attributes are written to the file as well, if they are numeric of string.
As igraph is more forgiving about attribute names, it might be neccessary to simplify the them before writing to the GML file. This way we'll have a syntactically correct GML file. The following simple procedure is performed on each attribute name: first the alphanumeric characters are extracted, the others are ignored. Then if the first character is not a letter then the attribute name is prefixed with <quote>igraph</quote>. Note that this might result identical names for two attributes, igraph does not check this.
The “id” vertex attribute is treated specially.
If the id
argument is not NULL
then it should be a numeric
vector with the vertex ids and the “id” vertex attribute is
ignored (if there is one). If id
is 0 and there is a
numeric id
vertex attribute that is used instead. If ids
are not specified in either way then the regular igraph vertex ids are used.
Note that whichever way vertex ids are specified, their uniqueness is not checked.
If the graph has edge attributes named “source” or “target” they're silently ignored. GML uses these attributes to specify the edges, so we cannot write them to the file. Rename them before calling this function if you want to preserve them.
Additional arguments:
NULL
or a numeric vector giving the vertex ids. See
details above.NULL
(the
default) then the current date and time is added.A NULL, invisibly.
Gabor Csardi csardi@rmki.kfki.hu
Adai AT, Date SV, Wieland S, Marcotte EM. LGL: creating a map of protein function with an algorithm for visualizing very large biological networks. J Mol Biol. 2004 Jun 25;340(1):179-90.
g <- graph.ring(10) ## Not run: write.graph(g, "/tmp/g.txt", "edgelist")